package com.shop2cn.iapi.sqrefund.testcase;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Comparator;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

import com.ymttest.business.service.shenqi.*;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.shop2cn.iapi.shenqisettlement.parameter.bean.AgentProductBean;
import com.shop2cn.iapi.sqoptrade.resp.Order;
import com.shop2cn.iapi.sqoptrade.resp.TradingServiceResp;
import com.shop2cn.iapi.sqrefund.parameter.PartProductRefundGoodsReq;
import com.shop2cn.iapi.sqrefund.parameter.bean.PartProductRefundVo;
import com.shop2cn.iapi.sqrefund.parameter.enums.CurrentMchRefundStatusEnum;
import com.shop2cn.iapi.sqrefund.service.PartProductRefundGoodsCall;
import com.ymatou.iapi.optrade.parameter.utill.Utils;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P3;
import com.ymttest.business.service.SQPayGateWayCallService;
import com.ymttest.business.service.shenqi.bean.PackageInfoByCatalogIdListResponse;
import com.ymttest.business.service.shenqi.bean.ShenqiUserSet;
import com.ymttest.database.model.sqrefund.RefundBill;
import com.ymttest.database.model.sqrefund.RefundBillIndex;
import com.ymttest.database.model.sqrefund.RefundProductDetail;
import com.ymttest.database.sharding.db.ext.model.OrderDetailExtPo;
import com.ymttest.database.sharding.db.sharding.model.OrderDetailPo;
import com.ymttest.database.sharding.db.sharding.model.OrderDetailSubCodePo;
import com.ymttest.database.sharding.db.sharding.model.OrderPo;
import com.ymttest.database.sharding.db.sharding.model.PaymentPo;
import com.ymttest.database.sharding.db.sharding.model.UserRefundFundDetailPo;
import com.ymttest.database.sharding.db.sqlwapper.OrderShardingWapper;
import com.ymttest.database.sharding.db.sqlwapper.OrderWapper;
import com.ymttest.database.sqlwapper.sqrefund.RefundBillIndexWrapper;
import com.ymttest.database.sqlwapper.sqrefund.RefundBillWrapper;
import com.ymttest.database.sqlwapper.sqrefund.RefundProductDetailWrapper;
import com.ymttest.utils.DataUtil;

/**
 * 发货 FreeMaker Template自动生成代码
 */
@TestSuite
public class Ts_PartProductRefundGoods {

	private static PartProductRefundGoodsReq partProductRefundGoodsReq;
	private static PartProductRefundGoodsCall partProductRefundGoodsCall;

	private static OrderShardingWapper orderShardingWapper = new OrderShardingWapper();
	private static OrderWapper orderWapper = new OrderWapper();

	private static RefundBillWrapper refundBillWrapper = new RefundBillWrapper();
	private static RefundProductDetailWrapper refundProductDetailWrapper = new RefundProductDetailWrapper();
	private static RefundBillIndexWrapper refundBillIndexWrapper = new RefundBillIndexWrapper();

	private static long autotest_goodsOwnerId = ShenqiUserSet.autotest_goodsOwnerId;
	private static long cdfMembergoodsOwnerId = ShenqiUserSet.cdfMembergoodsOwnerId;
	private static long multiCDFCodeGoodsOwnerId = ShenqiUserSet.multiCDFCodeGoodsOwnerId;
	private static long auditRefundGoodsOwnerId = ShenqiUserSet.auditRefundGoodsOwnerId;

	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("部分商品退货退款");
	}

	@Before
	public void caseUp() {

		partProductRefundGoodsReq = new PartProductRefundGoodsReq();
		partProductRefundGoodsCall = new PartProductRefundGoodsCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(partProductRefundGoodsCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}

	public void verify(long orderId) throws Exception {
		this.verify(orderId, null);
	}

	public void verify(long orderId, List<String> refundedBillNos)
			throws Exception {

		OrderPo orderPo = orderShardingWapper.selectOrderbyOrderId(orderId);

		List<OrderDetailPo> orderDetailPoList = orderShardingWapper
				.selectOrderDetailbyOrderId(orderId);

		orderDetailPoList = orderDetailPoList
				.stream()
				.sorted(Comparator.comparing(OrderDetailPo::getCatalogId)
						.reversed()).collect(Collectors.toList());

		List<PartProductRefundVo> partProductRefundVoList = partProductRefundGoodsReq
				.getPartProductRefundVoList();

		// 部分商品退货退款，每个商品一个退款单
		for (PartProductRefundVo partProductRefundVo : partProductRefundVoList) {

			RefundBill expectRefundBill = new RefundBill();

			Integer refundNum = partProductRefundVo.getRefundProductNum();

			BigDecimal refundFreightAmount = partProductRefundVo
					.getRefundFreightAmount();
			BigDecimal refundProductAmount = partProductRefundVo
					.getRefundProductAmount();
			BigDecimal refundTaxAmount = partProductRefundVo
					.getRefundTaxAmount();

			OrderDetailPo orderDetailPo = orderDetailPoList
					.stream()
					.filter(po -> po.getCatalogId().equalsIgnoreCase(
							partProductRefundVo.getCatalogId()))
					.collect(Collectors.toList()).get(0);

			int refundIntegral = new BigDecimal(Utils.zeroIfNull(orderDetailPo
					.getIntegral()))
					.multiply(new BigDecimal(refundNum))
					.divide(new BigDecimal(orderDetailPo.getProductCount()), 0,
							BigDecimal.ROUND_DOWN).intValue();
			
			BigDecimal refundServiceAmount = Utils
					.zeroIfNull(orderDetailPo.getServiceAmount())
					.multiply(new BigDecimal(refundNum))
					.divide(new BigDecimal(orderDetailPo.getProductCount()), 2,
							BigDecimal.ROUND_DOWN);

			// 创建expectRefundProductDetail
			RefundProductDetail expectRefundProductDetail = new RefundProductDetail();

			OrderDetailExtPo orderDetailExtPo = orderWapper
					.selectOrderDetailExtByOrderId(orderDetailPo
							.getOrderDetailId());

			expectRefundProductDetail.setOrder_id(orderId);
			expectRefundProductDetail.setCatalog_id(partProductRefundVo
					.getCatalogId());
			expectRefundProductDetail.setProduct_num(orderDetailPo
					.getProductCount());
			expectRefundProductDetail.setProduct_title(orderDetailExtPo
					.getTitle());
			expectRefundProductDetail
					.setRefund_product_amount(refundProductAmount);
			expectRefundProductDetail
					.setRefund_freight_amount(refundFreightAmount);
			expectRefundProductDetail.setRefund_tax_amount(refundTaxAmount);
			expectRefundProductDetail.setRefund_num(refundNum);

			expectRefundProductDetail.setRefund_integral((long) refundIntegral);
			
			expectRefundProductDetail.setRefund_service_amount(refundServiceAmount);

			String refundNo = this.verifyRefundProductDetailTable(
					expectRefundProductDetail, refundedBillNos);

			// 如果是一品多码商品
			if (orderPo.getGoodsOwnerId() == multiCDFCodeGoodsOwnerId
					&& orderPo.getOrderStatus() != 3) {

				List<OrderDetailSubCodePo> orderDetailSubCodePoList = orderShardingWapper
						.selectOrderDetailSubCodebyOrderIdAndCatalogId(orderId,
								expectRefundProductDetail.getCatalog_id());

				Integer actualCount = orderDetailSubCodePoList.stream()
						.map(detail -> detail.getRefundProductCount())
						.reduce(Integer::sum).orElse(0);

				if (orderDetailPo.getSubProduct()) {

					PackageInfoByCatalogIdListResponse response = SqTradingProductService
							.getPackageInfoByCatalogIdList(
									multiCDFCodeGoodsOwnerId,
									Arrays.asList(orderDetailPo.getCatalogId()));

					Integer totalCount = response.getProductPackageList()
							.get(0).getSubCatalogList().stream()
							.map(subPo -> subPo.getNum()).reduce(Integer::sum)
							.orElse(0);

					Logger.verifyEquals(
							expectRefundProductDetail.getRefund_num()
									* totalCount, actualCount, String.format(
									"验证%s子码退款数量",
									expectRefundProductDetail.getCatalog_id()));
				} else {

					Logger.verifyEquals(expectRefundProductDetail
							.getRefund_num(), actualCount, String.format(
							"验证%s子码退款数量",
							expectRefundProductDetail.getCatalog_id()));
				}
			}

			Long userId = orderPo.getUserId();
			Long applyUserId = 0L;
			String submitTradeResult = null;
			Integer refundStatus = 0;

			// 是否买家提交
			Boolean isUserApply = false;

			if (userId.intValue() == partProductRefundGoodsReq.getUserId()
					.intValue())
				isUserApply = true;

			if (isUserApply)
				applyUserId = userId;
			else {

				refundStatus = 3;
				applyUserId = partProductRefundGoodsReq.getCsId() == null ? partProductRefundGoodsReq
						.getUserId() : partProductRefundGoodsReq.getCsId();
			}

			expectRefundBill.setOrder_id(orderId);
			expectRefundBill.setRefund_type(4);
			expectRefundBill.setPlace_order_time(orderPo.getAddTime());
			expectRefundBill
					.setTotal_refund_product_amount(refundProductAmount);
			expectRefundBill.setTotal_refund_tax_amount(refundTaxAmount);
			expectRefundBill
					.setTotal_refund_freight_amount(refundFreightAmount);
			expectRefundBill.setOrder_status(orderPo.getOrderStatus());
			expectRefundBill.setSeller_id(orderPo.getSellerId());
			expectRefundBill.setGoods_owner_id(orderPo.getGoodsOwnerId());
			expectRefundBill.setUser_id(userId);
			expectRefundBill.setApply_user_id(applyUserId);
			expectRefundBill.setRefund_status(refundStatus);
			expectRefundBill
					.setCurrent_review_mch_id(orderPo.getGoodsOwnerId());
			expectRefundBill.setMch_review_status(isUserApply ? 0 : 2);
			expectRefundBill.setSubmit_trade_status(1);
			expectRefundBill.setRemark(partProductRefundGoodsReq.getRemark());
			expectRefundBill.setRefund_no(refundNo);
			expectRefundBill.setSubmit_trade_result(submitTradeResult);

			expectRefundBill.setTotal_refund_integral((long) refundIntegral);

			this.verifyRefundBillTable(orderId, expectRefundBill);

			RefundBillIndex expectResult = new RefundBillIndex();

			expectResult.setRefund_no(expectRefundBill.getRefund_no());
			expectResult.setMerchant_id(expectRefundBill.getSeller_id());
			expectResult.setOrder_status(expectRefundBill.getOrder_status());
			expectResult.setRefund_status(expectRefundBill.getRefund_status());
			expectResult.setOrder_id(orderId);
			expectResult.setRefund_type(expectRefundBill.getRefund_type());
			expectResult.setCurrent_review_mch_id(expectRefundBill
					.getCurrent_review_mch_id());
			expectResult.setMch_review_status(expectRefundBill
					.getMch_review_status());

			this.verifyRefundBillIndexTable(expectResult);

			if (refundStatus == 3) {

				boolean isAccountPaid = false;

				if (orderPo.getAccountPaidAmount().compareTo(BigDecimal.ZERO) == 1)
					isAccountPaid = true;
				else
					isAccountPaid = false;

				RefundService.buildUserRefundFundDetail(expectRefundBill,
						orderPo.getPaymentId(), isAccountPaid, refundServiceAmount);
			}
		}

		List<RefundBill> refundBills = refundBillWrapper
				.selectByOrderId(orderId);

		BigDecimal totalProductAmount = refundBills.stream()
				.map(RefundBill::getTotal_refund_product_amount)
				.reduce(BigDecimal.ZERO, BigDecimal::add);
		BigDecimal totalTaxAmount = refundBills.stream()
				.map(RefundBill::getTotal_refund_tax_amount)
				.reduce(BigDecimal.ZERO, BigDecimal::add);
		BigDecimal totalFreightAmount = refundBills.stream()
				.map(RefundBill::getTotal_refund_freight_amount)
				.reduce(BigDecimal.ZERO, BigDecimal::add);

		BigDecimal totalRefundAmount = totalProductAmount.add(totalTaxAmount)
				.add(totalFreightAmount);

		List<RefundProductDetail> refundProductDetailList = refundProductDetailWrapper
				.selectByOrderId(orderId);

		Integer totalRefundedNum = refundProductDetailList.stream()
				.map(RefundProductDetail::getRefund_num).reduce(Integer::sum)
				.orElse(0);

		Integer totalNum = orderDetailPoList.stream()
				.map(OrderDetailPo::getProductCount).reduce(Integer::sum)
				.orElse(0);

		// 如果商品未发货，商品或者订单金额全退，则订单取消

		if (orderPo.getOrderStatus() == 3) {
			Logger.verifyEquals(false,
					SqTradingCallService.isCanceledOrder(orderPo),
					"验证订单是否取消");
		} else {

			if ((orderPo.getOrderStatus() != 17)
					&& (totalRefundAmount.compareTo(orderPo.getPayableAmount()) == 0 || totalRefundedNum == totalNum))
				Logger.verifyEquals(true,
						SqTradingCallService.isCanceledOrder(orderPo),
						"验证订单是否取消");
			else
				Logger.verifyEquals(false,
						SqTradingCallService.isCanceledOrder(orderPo),
						"验证订单是否取消");
		}
	}

	private String verifyRefundBillTable(Long orderId, RefundBill expectResult) {

		String refundNo = expectResult.getRefund_no();

		Logger.comment(String.format("验证refund_bill表， orderId：%s，refundNo：%s",
				orderId, refundNo));

		RefundBill actualResult = refundBillWrapper.selectByRefundNoAndOrderId(
				orderId, refundNo);

		Logger.verifyEquals(expectResult.getRefund_type(),
				actualResult.getRefund_type(), "校验Refund_type");
		Logger.verifyEquals(refundNo, actualResult.getRefund_no(),
				"校验Refund_no");
		// DataUtil.verifyDateEquals(expectResult.getPlace_order_time(),
		// actualResult.getPlace_order_time(), "校验Place_order_time");
		DataUtil.verifyDecimalEquals(
				expectResult.getTotal_refund_product_amount(),
				actualResult.getTotal_refund_product_amount(),
				"校验Total_refund_product_amount");
		DataUtil.verifyDecimalEquals(expectResult.getTotal_refund_tax_amount(),
				actualResult.getTotal_refund_tax_amount(),
				"校验Total_refund_tax_amount");
		DataUtil.verifyDecimalEquals(
				expectResult.getTotal_refund_freight_amount(),
				actualResult.getTotal_refund_freight_amount(),
				"校验Total_refund_freight_amount");
		Logger.verifyEquals(expectResult.getOrder_status(),
				actualResult.getOrder_status(), "校验Order_status");
		Logger.verifyEquals(expectResult.getSeller_id(),
				actualResult.getSeller_id(), "校验Seller_id");
		Logger.verifyEquals(expectResult.getGoods_owner_id(),
				actualResult.getGoods_owner_id(), "校验Goods_owner_id");
		Logger.verifyEquals(expectResult.getUser_id(),
				actualResult.getUser_id(), "校验User_id");
		// DataUtil.verifyDateEquals(expectResult.getApply_time(),
		// actualResult.getApply_time(), "校验Apply_time");
		Logger.verifyEquals(expectResult.getApply_user_id(),
				actualResult.getApply_user_id(), "校验Apply_user_id");
		Logger.verifyEquals(expectResult.getRefund_status(),
				actualResult.getRefund_status(), "校验Refund_status");
		Logger.verifyEquals(expectResult.getCurrent_review_mch_id(),
				actualResult.getCurrent_review_mch_id(),
				"校验Current_review_mch_id");
		Logger.verifyEquals(expectResult.getMch_review_status(),
				actualResult.getMch_review_status(), "校验Mch_review_status");
		Logger.verifyEquals(expectResult.getSubmit_trade_result(),
				actualResult.getSubmit_trade_result(), "校验Submit_trade_result");
		Logger.verifyEquals(expectResult.getRemark(), actualResult.getRemark(),
				"校验Remark");

		Logger.verifyEquals(expectResult.getTotal_refund_integral(),
				actualResult.getTotal_refund_integral(),
				"校验Total_refund_integral");

		Logger.verifyEquals(partProductRefundGoodsReq.getLiabilityType(),
				actualResult.getLiability_type(), "校验Liability_type");
		Logger.verifyEquals(partProductRefundGoodsReq.getRefundExtType(),
				actualResult.getRefund_ext_type(), "校验Refund_ext_type");
		Logger.verifyEquals(partProductRefundGoodsReq.getRefundReasonCode(),
				actualResult.getRefund_reason_code(), "校验Refund_reason_code");
		Logger.verifyEquals(partProductRefundGoodsReq.getHasRefundGoods(),
				actualResult.getHas_refund_goods(), "校验Has_refund_goods");

		return actualResult.getRefund_no();
	}

	private String verifyRefundProductDetailTable(
			RefundProductDetail expectResult, List<String> refundedBillNos) {

		Long orderId = expectResult.getOrder_id();
		String catalogId = expectResult.getCatalog_id();

		Logger.comment(String.format(
				"验证refund_product_detail表， orderId：%s，catalogId：%s", orderId,
				catalogId));

		RefundProductDetail actualResult = null;

		if (null == refundedBillNos)
			refundedBillNos = Arrays.asList("");

		for (String refundedBillNo : refundedBillNos) {

			// 找到本次退款成功的退款单
			actualResult = refundProductDetailWrapper
					.selectLatestByOrderIdAndCatalogId(orderId, catalogId)
					.stream()
					.filter(refundProductDetail -> !refundProductDetail
							.getRefund_no().equalsIgnoreCase(refundedBillNo))
					.collect(Collectors.toList()).get(0);
		}

		DataUtil.verifyDecimalEquals(expectResult.getRefund_product_amount(),
				actualResult.getRefund_product_amount(),
				"校验Refund_product_amount");
		DataUtil.verifyDecimalEquals(expectResult.getRefund_tax_amount(),
				actualResult.getRefund_tax_amount(), "校验Refund_tax_amount");
		DataUtil.verifyDecimalEquals(expectResult.getRefund_freight_amount(),
				actualResult.getRefund_freight_amount(),
				"校验Refund_freight_amount");
		Logger.verifyEquals(expectResult.getRefund_num(),
				actualResult.getRefund_num(), "校验Refund_num");
		Logger.verifyEquals(expectResult.getProduct_num(),
				actualResult.getProduct_num(), "校验Product_num");
		Logger.verifyEquals(expectResult.getProduct_title(),
				actualResult.getProduct_title(), "校验Product_title");

		Logger.verifyEquals(expectResult.getRefund_integral(),
				actualResult.getRefund_integral(), "校验Refund_integral");
		
		Logger.verifyEquals(expectResult.getRefund_service_amount(),
				actualResult.getRefund_service_amount(), "校验Refund_service_amount");

		return actualResult.getRefund_no();
	}

	private void verifyRefundBillIndexTable(RefundBillIndex expectResult) {

		Long merchantId = expectResult.getMerchant_id();

		Logger.comment(String.format(
				"验证refund_bill_index表， refundNo：%s，merchantId：%s",
				expectResult.getRefund_no(), merchantId));

		// 找到退款成规的退款详情单
		RefundBillIndex actualResult = refundBillIndexWrapper
				.selectByRefundNoAndMerchantId(expectResult.getRefund_no(),
						merchantId);

		Logger.verifyEquals(expectResult.getOrder_status(),
				actualResult.getOrder_status(), "校验Order_status");
		Logger.verifyEquals(expectResult.getRefund_status(),
				actualResult.getRefund_status(), "校验Refund_status");
		Logger.verifyEquals(expectResult.getOrder_id(),
				actualResult.getOrder_id(), "校验Order_id");
		Logger.verifyEquals(expectResult.getRefund_type(),
				actualResult.getRefund_type(), "校验Refund_type");
		Logger.verifyEquals(expectResult.getCurrent_review_mch_id(),
				actualResult.getCurrent_review_mch_id(),
				"校验Current_review_mch_id");
		Logger.verifyEquals(expectResult.getMch_review_status(),
				actualResult.getMch_review_status(), "校验Mch_review_status");
	}

	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_PartProductRefundGoods_004() {
		Logger.start(false, "直销订单，已发货，货头申请部分退货退款");
		try {

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 0, false,
							false);

			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeOrder1(productBean, autotest_goodsOwnerId);

			Order order = placeOrderResp.getOrderList().get(0);

			long sellerId = order.getSellerId();
			Long userId = placeOrderResp.getUserId();

			long orderId = order.getOrderId();

			BigDecimal amount = placeOrderResp.getPayableAmount();

			SqTradingMqService.updateLiveOrder(false, orderId);

			// 支付订单
			Long thirdTradingId = SqTradingCallService.payOrder(userId,
					placeOrderResp.getTradingId());

			// 支付网关支付回调交易
			SQPayGateWayCallService.DGSQNotifyCall(
					String.valueOf(thirdTradingId),
					amount.subtract(BigDecimal.ZERO).toString(),
					userId.intValue(), BigDecimal.ZERO.toPlainString());

			Thread.sleep(5000);

			Long paymentId = orderShardingWapper.selectOrderbyOrderId(orderId)
					.getPaymentId();

			PaymentPo payment = orderShardingWapper
					.selectPaymentById(paymentId);

			ShenqiSettlementService.onHpSettled(paymentId, payment, null, 1);

			// 卖家接单
			SqTradingCallService.sellerAcceptOrder(sellerId, orderId);

			// 发货
			SqTradingCallService.delivery(sellerId, orderId, null, null);

			OrderDetailPo orderDetailPo = placeOrderResp.getOrderList().get(0)
					.getOrderDetailPoList().get(0);

			PartProductRefundVo partProductRefundVo = RefundService
					.buildPartProductRefundVo(orderDetailPo.getCatalogId(),
							BigDecimal.ONE, BigDecimal.ONE, BigDecimal.ONE, 1);

			partProductRefundGoodsReq.setUserId(autotest_goodsOwnerId);
			partProductRefundGoodsReq.setCsId(1234L);
			partProductRefundGoodsReq.setPartProductRefundVoList(Arrays
					.asList(partProductRefundVo));
			partProductRefundGoodsReq.setOrderId(orderId);
			partProductRefundGoodsReq.setRemark("部分退货退款");
			partProductRefundGoodsReq.setLiabilityType(1);
			partProductRefundGoodsReq.setRefundExtType(3);
			partProductRefundGoodsReq.setRefundReasonCode(-1);
			partProductRefundGoodsReq.setHasRefundGoods(false);

			partProductRefundGoodsCall.setData(partProductRefundGoodsReq);
			partProductRefundGoodsCall.callService();

			for (RefundBill refundBill : refundBillWrapper
					.selectByOrderId(orderId)) {

				String refundNo = refundBill.getRefund_no();

				// 审核地址
				RefundService.auditRefundGoods(autotest_goodsOwnerId,
						autotest_goodsOwnerId,
						CurrentMchRefundStatusEnum.LEVEL_ONE.getCode(),
						refundNo, true);

				// 上传运单信息
				RefundService.saveOrUpdateRefundGoodsExpressInfoList(
						autotest_goodsOwnerId, refundNo, autotest_goodsOwnerId);

				// 审核运单信息
				RefundService.auditRefund(autotest_goodsOwnerId,
						autotest_goodsOwnerId,
						CurrentMchRefundStatusEnum.GOODS.getCode(), refundNo,
						true);
			}
			
			// 退款服务同步到交易
			RefundService.syncNotSyncedRefundBill();

			// 退款提交到网关
			UserRefundFundDetailPo record = new UserRefundFundDetailPo();

			Calendar calendar = Calendar.getInstance();
			calendar.setTime(new Date());
			calendar.add(Calendar.MINUTE, -6);

			record.setPaymentId(paymentId);
			record.setUpdateTime(calendar.getTime());

			orderShardingWapper.userRefundFundDetailMapper
					.updateByPrimaryKeySelective(record);

			RefundService.supplementRefund(orderId);

			// 支付网关退款回调
			SQPayGateWayCallService.refundNotifyCall("13",
					paymentId.toString(), userId.intValue());

			Thread.sleep(3000);

			this.verify(orderId);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_PartProductRefundGoods_005() {
		Logger.start(false, "直销订单多个商品， 已发货，货头申请部分退货退款");
		try {

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 0, false,
							false);

			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeOrderWithMultiProsInOneOrder(productBean,
							BigDecimal.ONE);

			Order order = placeOrderResp.getOrderList().get(0);

			long sellerId = order.getSellerId();
			Long userId = placeOrderResp.getUserId();

			long orderId = order.getOrderId();

			BigDecimal amount = placeOrderResp.getPayableAmount();

			SqTradingMqService.updateLiveOrder(false, orderId);

			// 支付订单
			Long thirdTradingId = SqTradingCallService.payOrder(userId,
					placeOrderResp.getTradingId());

			// 支付网关支付回调交易
			SQPayGateWayCallService.DGSQNotifyCall(
					String.valueOf(thirdTradingId),
					amount.subtract(BigDecimal.ZERO).toString(),
					userId.intValue(), BigDecimal.ZERO.toPlainString());

			Thread.sleep(5000);

			Long paymentId = orderShardingWapper.selectOrderbyOrderId(orderId)
					.getPaymentId();

			PaymentPo payment = orderShardingWapper
					.selectPaymentById(paymentId);

			ShenqiSettlementService.onHpSettled(paymentId, payment, null, 1);

			// 卖家接单
			SqTradingCallService.sellerAcceptOrder(sellerId, orderId);

			// 发货
			SqTradingCallService.delivery(sellerId, orderId, null, null);

			OrderDetailPo orderDetailPo1 = placeOrderResp.getOrderList().get(0)
					.getOrderDetailPoList().get(0);

			PartProductRefundVo partProductRefundVo1 = RefundService
					.buildPartProductRefundVo(orderDetailPo1.getCatalogId(),
							BigDecimal.ONE, BigDecimal.ONE, BigDecimal.ONE, 1);

			OrderDetailPo orderDetailPo2 = placeOrderResp.getOrderList().get(0)
					.getOrderDetailPoList().get(1);

			PartProductRefundVo partProductRefundVo2 = RefundService
					.buildPartProductRefundVo(orderDetailPo2.getCatalogId(),
							BigDecimal.ONE, BigDecimal.ONE, BigDecimal.ONE, 1);

			partProductRefundGoodsReq.setUserId(autotest_goodsOwnerId);
			partProductRefundGoodsReq.setCsId(1234L);
			partProductRefundGoodsReq.setPartProductRefundVoList(Arrays.asList(
					partProductRefundVo1, partProductRefundVo2));
			partProductRefundGoodsReq.setOrderId(orderId);
			partProductRefundGoodsReq.setRemark("部分退货退款");
			partProductRefundGoodsReq.setLiabilityType(1);
			partProductRefundGoodsReq.setRefundExtType(3);
			partProductRefundGoodsReq.setRefundReasonCode(-1);
			partProductRefundGoodsReq.setHasRefundGoods(false);

			partProductRefundGoodsCall.setData(partProductRefundGoodsReq);
			partProductRefundGoodsCall.callService();

			for (RefundBill refundBill : refundBillWrapper
					.selectByOrderId(orderId)) {

				String refundNo = refundBill.getRefund_no();

				// 审核地址
				RefundService.auditRefundGoods(autotest_goodsOwnerId,
						autotest_goodsOwnerId,
						CurrentMchRefundStatusEnum.LEVEL_ONE.getCode(),
						refundNo, true);

				// 上传运单信息
				RefundService.saveOrUpdateRefundGoodsExpressInfoList(
						autotest_goodsOwnerId, refundNo, autotest_goodsOwnerId);

				// 审核运单信息
				RefundService.auditRefund(autotest_goodsOwnerId,
						autotest_goodsOwnerId,
						CurrentMchRefundStatusEnum.GOODS.getCode(), refundNo,
						true);
			}

			// 退款服务同步到交易
			RefundService.syncNotSyncedRefundBill();

			// 退款提交到网关
			UserRefundFundDetailPo record = new UserRefundFundDetailPo();

			Calendar calendar = Calendar.getInstance();
			calendar.setTime(new Date());
			calendar.add(Calendar.MINUTE, -6);

			record.setPaymentId(paymentId);
			record.setUpdateTime(calendar.getTime());

			orderShardingWapper.userRefundFundDetailMapper
					.updateByPrimaryKeySelective(record);

			RefundService.supplementRefund(orderId);

			// 支付网关退款回调
			SQPayGateWayCallService.refundNotifyCall("13",
					paymentId.toString(), userId.intValue());

			Thread.sleep(3000);

			this.verify(orderId);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_PartProductRefundGoods_006() {
		Logger.start(false, "直销订单，已经整单退款成功的订单，再次部分退款，退款失败");
		try {

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 0, false,
							false);

			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeOrder1(productBean, autotest_goodsOwnerId);

			Order order = placeOrderResp.getOrderList().get(0);

			long sellerId = order.getSellerId();
			Long userId = placeOrderResp.getUserId();

			long orderId = order.getOrderId();

			BigDecimal amount = placeOrderResp.getPayableAmount();

			SqTradingMqService.updateLiveOrder(false, orderId);

			// 支付订单
			Long thirdTradingId = SqTradingCallService.payOrder(userId,
					placeOrderResp.getTradingId());

			// 支付网关支付回调交易
			SQPayGateWayCallService.DGSQNotifyCall(
					String.valueOf(thirdTradingId),
					amount.subtract(BigDecimal.ZERO).toString(),
					userId.intValue(), BigDecimal.ZERO.toPlainString());

			Thread.sleep(5000);

			Long paymentId = orderShardingWapper.selectOrderbyOrderId(orderId)
					.getPaymentId();

			PaymentPo payment = orderShardingWapper
					.selectPaymentById(paymentId);

			ShenqiSettlementService.onHpSettled(paymentId, payment, null, 1);

			// 卖家接单
			SqTradingCallService.sellerAcceptOrder(sellerId, orderId);

			// 发货
			SqTradingCallService.delivery(sellerId, orderId, null, null);

			// 创建一个整单退款的退款单
			RefundService.createFullRefundSuccess(orderId,
					autotest_goodsOwnerId, paymentId, userId);

			OrderDetailPo orderDetailPo = placeOrderResp.getOrderList().get(0)
					.getOrderDetailPoList().get(0);
			int refundProductCount = 1;

			BigDecimal refundTaxAmount = RefundService
					.getOrderDetailTaxFeeAmount(orderDetailPo,
							refundProductCount);
			BigDecimal refundProductAmount = RefundService
					.getOrderDetailPoMaxRefundAmount(orderId, orderDetailPo,
							refundProductCount);

			PartProductRefundVo partProductRefundVo = RefundService
					.buildPartProductRefundVo(orderDetailPo.getCatalogId(),
							BigDecimal.ZERO, refundProductAmount,
							refundTaxAmount, refundProductCount);

			partProductRefundGoodsReq.setUserId(autotest_goodsOwnerId);
			partProductRefundGoodsReq.setCsId(1234L);
			partProductRefundGoodsReq.setPartProductRefundVoList(Arrays
					.asList(partProductRefundVo));
			partProductRefundGoodsReq.setOrderId(orderId);
			partProductRefundGoodsReq.setRemark("部分退货退款");
			partProductRefundGoodsReq.setLiabilityType(1);
			partProductRefundGoodsReq.setRefundExtType(3);
			partProductRefundGoodsReq.setRefundReasonCode(-1);
			partProductRefundGoodsReq.setHasRefundGoods(false);

			partProductRefundGoodsCall.setData(partProductRefundGoodsReq);
			partProductRefundGoodsCall.callService();

			Logger.verifyEquals(
					"没有可以退的商品",
					partProductRefundGoodsCall.getMsg(), "验证resultMessage");
			Logger.verifyEquals("3", partProductRefundGoodsCall.getCode(),
					"验证resultCode");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_PartProductRefundGoods_007() {
		Logger.start(false, "直销订单，当前商品正在退款，再次部分退款，退款失败");
		try {

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 0, false,
							false);

			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeOrder1(productBean, autotest_goodsOwnerId);

			Order order = placeOrderResp.getOrderList().get(0);

			long sellerId = order.getSellerId();
			Long userId = placeOrderResp.getUserId();

			long orderId = order.getOrderId();

			BigDecimal amount = placeOrderResp.getPayableAmount();

			// 支付订单
			Long thirdTradingId = SqTradingCallService.payOrder(userId,
					placeOrderResp.getTradingId());

			// 支付网关支付回调交易
			SQPayGateWayCallService.DGSQNotifyCall(
					String.valueOf(thirdTradingId),
					amount.subtract(BigDecimal.ZERO).toString(),
					userId.intValue(), BigDecimal.ZERO.toPlainString());

			Thread.sleep(5000);

			// 卖家接单
			SqTradingCallService.sellerAcceptOrder(sellerId, orderId);

			// 发货
			SqTradingCallService.delivery(sellerId, orderId, null, null);

			OrderDetailPo orderDetailPo = placeOrderResp.getOrderList().get(0)
					.getOrderDetailPoList().get(0);

			PartProductRefundVo partProductRefundVo = RefundService
					.buildPartProductRefundVo(orderDetailPo.getCatalogId(),
							BigDecimal.ONE, BigDecimal.ONE, BigDecimal.ONE, 1);

			partProductRefundGoodsReq.setUserId(autotest_goodsOwnerId);
			partProductRefundGoodsReq.setCsId(1234L);
			partProductRefundGoodsReq.setPartProductRefundVoList(Arrays
					.asList(partProductRefundVo));
			partProductRefundGoodsReq.setOrderId(orderId);
			partProductRefundGoodsReq.setRemark("部分退货退款");
			partProductRefundGoodsReq.setLiabilityType(1);
			partProductRefundGoodsReq.setRefundExtType(3);
			partProductRefundGoodsReq.setRefundReasonCode(-1);
			partProductRefundGoodsReq.setHasRefundGoods(false);

			partProductRefundGoodsCall.setData(partProductRefundGoodsReq);
			partProductRefundGoodsCall.callService();

			// 再次申请部分退货退款
			partProductRefundGoodsCall.callService();

			Logger.verifyEquals("没有可以退的商品",
					partProductRefundGoodsCall.getMsg(), "验证resultMessage");
			Logger.verifyEquals("3", partProductRefundGoodsCall.getCode(),
					"验证resultCode");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_PartProductRefundGoods_008() {
		Logger.start(false, "直销订单，订单整单退款被拒绝，再次部分退货退款，退款成功");
		try {

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createProxychain((int) auditRefundGoodsOwnerId, 0, false,
							false);

			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeOrder1(productBean, auditRefundGoodsOwnerId);

			Order order = placeOrderResp.getOrderList().get(0);

			long sellerId = order.getSellerId();
			Long userId = placeOrderResp.getUserId();

			long orderId = order.getOrderId();

			BigDecimal amount = placeOrderResp.getPayableAmount();

			SqTradingMqService.updateLiveOrder(false, orderId);

			// 支付订单
			Long thirdTradingId = SqTradingCallService.payOrder(userId,
					placeOrderResp.getTradingId());

			// 支付网关支付回调交易
			SQPayGateWayCallService.DGSQNotifyCall(
					String.valueOf(thirdTradingId),
					amount.subtract(BigDecimal.ZERO).toString(),
					userId.intValue(), BigDecimal.ZERO.toPlainString());

			Thread.sleep(5000);

			Long paymentId = orderShardingWapper.selectOrderbyOrderId(orderId)
					.getPaymentId();

			PaymentPo payment = orderShardingWapper
					.selectPaymentById(paymentId);

			ShenqiSettlementService.onHpSettled(paymentId, payment, null, 1);

			// 卖家接单
			SqTradingCallService.sellerAcceptOrder(sellerId, orderId);

			// 发货
			SqTradingCallService.delivery(sellerId, orderId, null, null);

			// 创建一个整单退款被拒绝的订单
			String refundedBillNo = RefundService.createFullRefundRejected(
					orderId, auditRefundGoodsOwnerId, paymentId);

			OrderDetailPo orderDetailPo = placeOrderResp.getOrderList().get(0)
					.getOrderDetailPoList().get(0);

			PartProductRefundVo partProductRefundVo = RefundService
					.buildPartProductRefundVo(orderDetailPo.getCatalogId(),
							BigDecimal.ONE, BigDecimal.ONE, BigDecimal.ONE, 1);

			partProductRefundGoodsReq.setUserId(auditRefundGoodsOwnerId);
			partProductRefundGoodsReq.setCsId(1234L);
			partProductRefundGoodsReq.setPartProductRefundVoList(Arrays
					.asList(partProductRefundVo));
			partProductRefundGoodsReq.setOrderId(orderId);
			partProductRefundGoodsReq.setRemark("部分退货退款");
			partProductRefundGoodsReq.setLiabilityType(1);
			partProductRefundGoodsReq.setRefundExtType(3);
			partProductRefundGoodsReq.setRefundReasonCode(-1);
			partProductRefundGoodsReq.setHasRefundGoods(false);

			partProductRefundGoodsCall.setData(partProductRefundGoodsReq);
			partProductRefundGoodsCall.callService();

			// 第一个退款单已经被拒绝，取第二个退款单
			RefundBill refundBill = refundBillWrapper
					.selectByOrderId(orderId).get(1);
			String refundNo = refundBill.getRefund_no();

			// 审核地址
			RefundService.auditRefundGoods(auditRefundGoodsOwnerId, auditRefundGoodsOwnerId,
					CurrentMchRefundStatusEnum.LEVEL_ONE.getCode(), refundNo, true);

			// 二级审核通过
			RefundService.auditRefund(auditRefundGoodsOwnerId, auditRefundGoodsOwnerId,
					CurrentMchRefundStatusEnum.LEVEL_TWO.getCode(), refundNo, true);

			// 填写物流单号
			RefundService.saveOrUpdateRefundGoodsExpressInfoList(
					auditRefundGoodsOwnerId, refundNo, auditRefundGoodsOwnerId);

			// 审核运单信息
			RefundService.auditRefund(auditRefundGoodsOwnerId, auditRefundGoodsOwnerId,
					CurrentMchRefundStatusEnum.GOODS.getCode(), refundNo, true);

			// 退款服务同步到交易
			RefundService.syncNotSyncedRefundBill();

			// 退款提交到网关
			UserRefundFundDetailPo record = new UserRefundFundDetailPo();

			Calendar calendar = Calendar.getInstance();
			calendar.setTime(new Date());
			calendar.add(Calendar.MINUTE, -6);

			record.setPaymentId(paymentId);
			record.setUpdateTime(calendar.getTime());

			orderShardingWapper.userRefundFundDetailMapper
					.updateByPrimaryKeySelective(record);

			RefundService.supplementRefund(orderId);

			// 支付网关退款回调
			SQPayGateWayCallService.refundNotifyCall("13",
					paymentId.toString(), userId.intValue());

			Thread.sleep(3000);

			this.verify(orderId, Arrays.asList(refundedBillNo));

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_PartProductRefundGoods_009() {
		Logger.start(false, "代理订单，多商品订单，依次退货退款，退款成功");
		try {

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 1, false,
							false);

			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeOrderWithMultiProsInOneOrder(productBean,
							new BigDecimal("0.17"));

			Order order = placeOrderResp.getOrderList().get(0);

			Long userId = placeOrderResp.getUserId();

			long orderId = order.getOrderId();

			BigDecimal amount = placeOrderResp.getPayableAmount();

			SqTradingMqService.updateLiveOrder(false, orderId);

			// 支付订单
			Long thirdTradingId = SqTradingCallService.payOrder(userId,
					placeOrderResp.getTradingId());

			// 支付网关支付回调交易
			SQPayGateWayCallService.DGSQNotifyCall(
					String.valueOf(thirdTradingId),
					amount.subtract(BigDecimal.ZERO).toString(),
					userId.intValue(), BigDecimal.ZERO.toPlainString());

			Thread.sleep(5000);

			Long paymentId = orderShardingWapper.selectOrderbyOrderId(orderId)
					.getPaymentId();

			PaymentPo payment = orderShardingWapper
					.selectPaymentById(paymentId);

			ShenqiSettlementService.onHpSettled(paymentId, payment, null, 1);

			// 卖家接单
			SqTradingCallService.sellerAcceptOrder(autotest_goodsOwnerId,
					orderId);

			// 发货
			SqTradingCallService.delivery(autotest_goodsOwnerId, orderId,
					null, null);

			int count = 0;

			for (OrderDetailPo orderDetailPo : order.getOrderDetailPoList()) {

				int refundCount = orderDetailPo.getProductCount();

				BigDecimal refundTaxAmount = RefundService
						.getOrderDetailTaxFeeAmount(orderDetailPo, refundCount);
				BigDecimal refundProductAmount = RefundService
						.getOrderDetailPaidAmountExcludeFreight(orderDetailPo,
								refundCount, false);
				BigDecimal refundFreightAmount = RefundService
						.getMaxCanRefundFreight(orderDetailPo,
								orderDetailPo.getFreight());

				PartProductRefundVo partProductRefundVo = RefundService
						.buildPartProductRefundVo(orderDetailPo.getCatalogId(),
								refundFreightAmount, refundProductAmount,
								refundTaxAmount, refundCount);

				partProductRefundGoodsReq.setUserId(autotest_goodsOwnerId);
				partProductRefundGoodsReq.setCsId(1234L);
				partProductRefundGoodsReq.setPartProductRefundVoList(Arrays
						.asList(partProductRefundVo));
				partProductRefundGoodsReq.setOrderId(orderId);
				partProductRefundGoodsReq.setRemark("部分退货退款");
				partProductRefundGoodsReq.setLiabilityType(1);
				partProductRefundGoodsReq.setRefundExtType(3);
				partProductRefundGoodsReq.setRefundReasonCode(-1);
				partProductRefundGoodsReq.setHasRefundGoods(false);

				partProductRefundGoodsCall.setData(partProductRefundGoodsReq);
				partProductRefundGoodsCall.callService();

				RefundBill refundBill = refundBillWrapper.selectByOrderId(
						orderId).get(count);

				String refundNo = refundBill.getRefund_no();

				// 审核地址
				RefundService.auditRefundGoods(autotest_goodsOwnerId,
						autotest_goodsOwnerId,
						CurrentMchRefundStatusEnum.LEVEL_ONE.getCode(),
						refundNo, true);

				// 上传运单信息
				RefundService.saveOrUpdateRefundGoodsExpressInfoList(
						autotest_goodsOwnerId, refundNo, autotest_goodsOwnerId);

				// 审核运单信息
				RefundService.auditRefund(autotest_goodsOwnerId,
						autotest_goodsOwnerId,
						CurrentMchRefundStatusEnum.GOODS.getCode(), refundNo,
						true);

				// 退款服务同步到交易
				RefundService.syncNotSyncedRefundBill();


				// 退款提交到网关
				UserRefundFundDetailPo record = new UserRefundFundDetailPo();

				Calendar calendar = Calendar.getInstance();
				calendar.setTime(new Date());
				calendar.add(Calendar.MINUTE, -6);

				record.setPaymentId(paymentId);
				record.setUpdateTime(calendar.getTime());

				orderShardingWapper.userRefundFundDetailMapper
						.updateByPrimaryKeySelective(record);

				RefundService.supplementRefund(orderId);

				// 支付网关退款回调
				SQPayGateWayCallService.refundNotifyCall("13",
						paymentId.toString(), userId.intValue());

				Thread.sleep(3000);

				this.verify(orderId);

				count = count + 1;
			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_PartProductRefundGoods_010() {
		Logger.start(false, "直销订单，已有仅退款成功的订单，再次部分退货退款，退款成功");
		try {

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 0, false,
							false);

			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeOrder1(productBean, autotest_goodsOwnerId);

			Order order = placeOrderResp.getOrderList().get(0);

			long sellerId = order.getSellerId();
			Long userId = placeOrderResp.getUserId();

			long orderId = order.getOrderId();

			BigDecimal amount = placeOrderResp.getPayableAmount();

			SqTradingMqService.updateLiveOrder(false, orderId);

			// 支付订单
			Long thirdTradingId = SqTradingCallService.payOrder(userId,
					placeOrderResp.getTradingId());

			// 支付网关支付回调交易
			SQPayGateWayCallService.DGSQNotifyCall(
					String.valueOf(thirdTradingId),
					amount.subtract(BigDecimal.ZERO).toString(),
					userId.intValue(), BigDecimal.ZERO.toPlainString());

			Thread.sleep(5000);

			Long paymentId = orderShardingWapper.selectOrderbyOrderId(orderId)
					.getPaymentId();

			PaymentPo payment = orderShardingWapper
					.selectPaymentById(paymentId);

			ShenqiSettlementService.onHpSettled(paymentId, payment, null, 1);

			// 卖家接单
			SqTradingCallService.sellerAcceptOrder(sellerId, orderId);

			// 发货
			SqTradingCallService.delivery(autotest_goodsOwnerId, orderId,
					null, null);

			// 创建一个部分退款成功的退款单
			String refundBillNo = RefundService.createPartAmountRefundSuccess(
					orderId, sellerId, paymentId, userId, BigDecimal.TEN);

			OrderDetailPo orderDetailPo = placeOrderResp.getOrderList().get(0)
					.getOrderDetailPoList().get(0);

			PartProductRefundVo partProductRefundVo = RefundService
					.buildPartProductRefundVo(orderDetailPo.getCatalogId(),
							BigDecimal.ONE, BigDecimal.ONE, BigDecimal.ONE, 1);

			partProductRefundGoodsReq.setUserId(autotest_goodsOwnerId);
			partProductRefundGoodsReq.setCsId(1234L);
			partProductRefundGoodsReq.setPartProductRefundVoList(Arrays
					.asList(partProductRefundVo));
			partProductRefundGoodsReq.setOrderId(orderId);
			partProductRefundGoodsReq.setRemark("部分退货退款");
			partProductRefundGoodsReq.setLiabilityType(1);
			partProductRefundGoodsReq.setRefundExtType(3);
			partProductRefundGoodsReq.setRefundReasonCode(-1);
			partProductRefundGoodsReq.setHasRefundGoods(false);

			partProductRefundGoodsCall.setData(partProductRefundGoodsReq);
			partProductRefundGoodsCall.callService();

			for (RefundBill refundBill : refundBillWrapper
					.selectByOrderId(orderId)) {

				String refundNo = refundBill.getRefund_no();

				// 审核地址
				RefundService.auditRefundGoods(autotest_goodsOwnerId,
						autotest_goodsOwnerId,
						CurrentMchRefundStatusEnum.LEVEL_ONE.getCode(),
						refundNo, true);

				// 上传运单信息
				RefundService.saveOrUpdateRefundGoodsExpressInfoList(
						autotest_goodsOwnerId, refundNo, autotest_goodsOwnerId);

				// 审核运单信息
				RefundService.auditRefund(autotest_goodsOwnerId,
						autotest_goodsOwnerId,
						CurrentMchRefundStatusEnum.GOODS.getCode(), refundNo,
						true);
			}

			// 退款服务同步到交易
			RefundService.syncNotSyncedRefundBill();

			// 退款提交到网关
			UserRefundFundDetailPo record = new UserRefundFundDetailPo();

			Calendar calendar = Calendar.getInstance();
			calendar.setTime(new Date());
			calendar.add(Calendar.MINUTE, -6);

			record.setPaymentId(paymentId);
			record.setUpdateTime(calendar.getTime());

			orderShardingWapper.userRefundFundDetailMapper
					.updateByPrimaryKeySelective(record);

			RefundService.supplementRefund(orderId);

			// 支付网关退款回调
			SQPayGateWayCallService.refundNotifyCall("13",
					paymentId.toString(), userId.intValue());

			Thread.sleep(3000);

			this.verify(orderId, Arrays.asList(refundBillNo));

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_PartProductRefundGoods_011() {
		Logger.start(false, "直销订单，盛付通支付，已发货，货头申请部分退货退款，退款成功");
		try {

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 0, false,
							false);

			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeOrder1(productBean, autotest_goodsOwnerId);

			Order order = placeOrderResp.getOrderList().get(0);

			long sellerId = order.getSellerId();
			Long userId = placeOrderResp.getUserId();

			long orderId = order.getOrderId();

			BigDecimal amount = placeOrderResp.getPayableAmount();

			SqTradingMqService.updateLiveOrder(false, orderId);

			// 支付订单
			Long thirdTradingId = SqTradingCallService.payOrder(userId,
					placeOrderResp.getTradingId(), "wxsqBuyer", "6010");

			// 支付网关支付回调交易
			SQPayGateWayCallService.DGSQNotifyCall(
					String.valueOf(thirdTradingId),
					amount.subtract(BigDecimal.ZERO).toString(),
					userId.intValue(), BigDecimal.ZERO.toPlainString(), 6010);

			Thread.sleep(5000);

			Long paymentId = orderShardingWapper.selectOrderbyOrderId(orderId)
					.getPaymentId();

			PaymentPo payment = orderShardingWapper
					.selectPaymentById(paymentId);

			ShenqiSettlementService.onHpSettled(paymentId, payment, null, 1);

			// 卖家接单
			SqTradingCallService.sellerAcceptOrder(sellerId, orderId);

			// 发货
			SqTradingCallService.delivery(autotest_goodsOwnerId, orderId,
					null, null);

			OrderDetailPo orderDetailPo = placeOrderResp.getOrderList().get(0)
					.getOrderDetailPoList().get(0);

			PartProductRefundVo partProductRefundVo = RefundService
					.buildPartProductRefundVo(orderDetailPo.getCatalogId(),
							BigDecimal.ONE, BigDecimal.ONE, BigDecimal.ONE, 1);

			partProductRefundGoodsReq.setUserId(autotest_goodsOwnerId);
			partProductRefundGoodsReq.setCsId(1234L);
			partProductRefundGoodsReq.setPartProductRefundVoList(Arrays
					.asList(partProductRefundVo));
			partProductRefundGoodsReq.setOrderId(orderId);
			partProductRefundGoodsReq.setRemark("部分退货退款");
			partProductRefundGoodsReq.setLiabilityType(1);
			partProductRefundGoodsReq.setRefundExtType(3);
			partProductRefundGoodsReq.setRefundReasonCode(-1);
			partProductRefundGoodsReq.setHasRefundGoods(false);

			partProductRefundGoodsCall.setData(partProductRefundGoodsReq);
			partProductRefundGoodsCall.callService();

			for (RefundBill refundBill : refundBillWrapper
					.selectByOrderId(orderId)) {

				String refundNo = refundBill.getRefund_no();

				// 审核地址
				RefundService.auditRefundGoods(autotest_goodsOwnerId,
						autotest_goodsOwnerId,
						CurrentMchRefundStatusEnum.LEVEL_ONE.getCode(),
						refundNo, true);

				// 上传运单信息
				RefundService.saveOrUpdateRefundGoodsExpressInfoList(
						autotest_goodsOwnerId, refundNo, autotest_goodsOwnerId);

				// 审核运单信息
				RefundService.auditRefund(autotest_goodsOwnerId,
						autotest_goodsOwnerId,
						CurrentMchRefundStatusEnum.GOODS.getCode(), refundNo,
						true);
			}

			// 退款服务同步到交易
			RefundService.syncNotSyncedRefundBill();

			// 退款提交到网关
			UserRefundFundDetailPo record = new UserRefundFundDetailPo();

			Calendar calendar = Calendar.getInstance();
			calendar.setTime(new Date());
			calendar.add(Calendar.MINUTE, -6);

			record.setPaymentId(paymentId);
			record.setUpdateTime(calendar.getTime());

			orderShardingWapper.userRefundFundDetailMapper
					.updateByPrimaryKeySelective(record);

			RefundService.supplementRefund(orderId);

			// 支付网关退款回调
			SQPayGateWayCallService.refundNotifyCall("13",
					paymentId.toString(), userId.intValue());

			Thread.sleep(3000);

			this.verify(orderId);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_PartProductRefundGoods_012() {
		Logger.start(false, "直销订单，超过90天的订单，已发货，货头申请部分退货退款，退款失败");
		try {

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 0, false,
							false);

			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeOrder1(productBean, autotest_goodsOwnerId);

			Order order = placeOrderResp.getOrderList().get(0);

			long sellerId = order.getSellerId();
			Long userId = placeOrderResp.getUserId();

			long orderId = order.getOrderId();

			BigDecimal amount = placeOrderResp.getPayableAmount();

			// 支付订单
			Long thirdTradingId = SqTradingCallService.payOrder(userId,
					placeOrderResp.getTradingId());

			// 支付网关支付回调交易
			SQPayGateWayCallService.DGSQNotifyCall(
					String.valueOf(thirdTradingId),
					amount.subtract(BigDecimal.ZERO).toString(),
					userId.intValue(), BigDecimal.ZERO.toPlainString());

			Thread.sleep(5000);

			// 修改支付时间为90天前
			OrderPo record = new OrderPo();

			Calendar calendar = Calendar.getInstance();
			calendar.setTime(new Date());
			calendar.add(Calendar.DAY_OF_MONTH, -101);

			record.setOrderId(orderId);
			record.setPaidTime(calendar.getTime());

			orderShardingWapper.orderMapper.updateByPrimaryKeySelective(record);

			// 卖家接单
			SqTradingCallService.sellerAcceptOrder(sellerId, orderId);

			// 发货
			SqTradingCallService.delivery(autotest_goodsOwnerId, orderId,
					null, null);

			OrderDetailPo orderDetailPo = placeOrderResp.getOrderList().get(0)
					.getOrderDetailPoList().get(0);

			PartProductRefundVo partProductRefundVo = RefundService
					.buildPartProductRefundVo(orderDetailPo.getCatalogId(),
							BigDecimal.ONE, BigDecimal.ONE, BigDecimal.ONE, 1);

			partProductRefundGoodsReq.setUserId(autotest_goodsOwnerId);
			partProductRefundGoodsReq.setCsId(1234L);
			partProductRefundGoodsReq.setPartProductRefundVoList(Arrays
					.asList(partProductRefundVo));
			partProductRefundGoodsReq.setOrderId(orderId);
			partProductRefundGoodsReq.setRemark("部分退货退款");
			partProductRefundGoodsReq.setLiabilityType(1);
			partProductRefundGoodsReq.setRefundExtType(3);
			partProductRefundGoodsReq.setRefundReasonCode(-1);
			partProductRefundGoodsReq.setHasRefundGoods(false);

			partProductRefundGoodsCall.setData(partProductRefundGoodsReq);
			partProductRefundGoodsCall.callService();

			Logger.verifyEquals("订单已支付超过90天无法发起退款",
					partProductRefundGoodsCall.getMsg(), "验证resultMessage");
			Logger.verifyEquals("3", partProductRefundGoodsCall.getCode(),
					"验证resultCode");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P3.class)
	@TestCase
	@Ignore
	public void Tc_PartProductRefundGoods_016() {
		Logger.start(false, "直销订单，已核销的虚拟库存，已发货，货头申请部分退货退款");
		try {

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 0, false);
			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeOrder1(productBean, autotest_goodsOwnerId, 2);

			Order order = placeOrderResp.getOrderList().get(0);

			long sellerId = order.getSellerId();
			Long userId = placeOrderResp.getUserId();

			long orderId = order.getOrderId();

			BigDecimal amount = placeOrderResp.getPayableAmount();

			SqTradingMqService.updateLiveOrder(false, orderId);

			// 支付订单
			Long thirdTradingId = SqTradingCallService.payOrder(userId,
					placeOrderResp.getTradingId());

			// 支付网关支付回调交易
			SQPayGateWayCallService.DGSQNotifyCall(
					String.valueOf(thirdTradingId),
					amount.subtract(BigDecimal.ZERO).toString(),
					userId.intValue(), BigDecimal.ZERO.toPlainString());

			Thread.sleep(5000);

			Long paymentId = orderShardingWapper.selectOrderbyOrderId(orderId)
					.getPaymentId();

			PaymentPo payment = orderShardingWapper
					.selectPaymentById(paymentId);

			ShenqiSettlementService.onHpSettled(thirdTradingId, payment,
					null, 1);

			// 卖家接单
			SqTradingCallService.sellerAcceptOrder(sellerId, orderId);

			OrderDetailPo orderDetailPo = placeOrderResp.getOrderList().get(0)
					.getOrderDetailPoList().get(0);

			// 先入库，再核销
			SqTradingCallService.stockIn(autotest_goodsOwnerId,
					orderDetailPo.getProductId(), 2);

			SqTradingCallService.sqStockChangeNotify(productBean);

			// 发货
			SqTradingCallService.delivery(autotest_goodsOwnerId, orderId,
					null, null);

			PartProductRefundVo partProductRefundVo = RefundService
					.buildPartProductRefundVo(orderDetailPo.getCatalogId(),
							BigDecimal.ONE, BigDecimal.ONE, BigDecimal.ONE,
							orderDetailPo.getProductCount());

			partProductRefundGoodsReq.setUserId(autotest_goodsOwnerId);
			partProductRefundGoodsReq.setCsId(1234L);
			partProductRefundGoodsReq.setPartProductRefundVoList(Arrays
					.asList(partProductRefundVo));
			partProductRefundGoodsReq.setOrderId(orderId);
			partProductRefundGoodsReq.setRemark("部分退货退款");
			partProductRefundGoodsReq.setLiabilityType(1);
			partProductRefundGoodsReq.setRefundExtType(3);
			partProductRefundGoodsReq.setRefundReasonCode(-1);
			partProductRefundGoodsReq.setHasRefundGoods(false);

			partProductRefundGoodsCall.setData(partProductRefundGoodsReq);
			partProductRefundGoodsCall.callService();

			Logger.verifyEquals("抱歉，虚拟库存未核销不支持修改退款商品数量",
					partProductRefundGoodsCall.getMsg(), "验证resultMessage");
			Logger.verifyEquals("3", partProductRefundGoodsCall.getCode(),
					"验证resultCode");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_PartProductRefundGoods_017() {
		Logger.start(false, "直销订单，带有服务费率，已发货，货头申请部分退款");
		try {

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 0, false,
							false);

			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeOrderWithServiceRate(productBean);

			Order order = placeOrderResp.getOrderList().get(0);

			long sellerId = order.getSellerId();
			Long userId = placeOrderResp.getUserId();

			long orderId = order.getOrderId();

			BigDecimal amount = placeOrderResp.getPayableAmount();

			SqTradingMqService.updateLiveOrder(false, orderId);

			// 支付订单
			Long thirdTradingId = SqTradingCallService.payOrder(userId,
					placeOrderResp.getTradingId());

			// 支付网关支付回调交易
			SQPayGateWayCallService.DGSQNotifyCall(
					String.valueOf(thirdTradingId),
					amount.subtract(BigDecimal.ZERO).toString(),
					userId.intValue(), BigDecimal.ZERO.toPlainString());

			Thread.sleep(5000);

			Long paymentId = orderShardingWapper.selectOrderbyOrderId(orderId)
					.getPaymentId();

			PaymentPo payment = orderShardingWapper
					.selectPaymentById(paymentId);

			ShenqiSettlementService.onHpSettled(paymentId, payment, null, 1);

			// 卖家接单
			SqTradingCallService.sellerAcceptOrder(sellerId, orderId);

			// 发货
			SqTradingCallService.delivery(autotest_goodsOwnerId, orderId,
					null, null);

			OrderDetailPo orderDetailPo = placeOrderResp.getOrderList().get(0)
					.getOrderDetailPoList().get(0);

			PartProductRefundVo partProductRefundVo = RefundService
					.buildPartProductRefundVo(orderDetailPo.getCatalogId(),
							BigDecimal.ZERO, BigDecimal.ONE, BigDecimal.ZERO,
							orderDetailPo.getProductCount());

			partProductRefundGoodsReq.setUserId(autotest_goodsOwnerId);
			partProductRefundGoodsReq.setCsId(1234L);
			partProductRefundGoodsReq.setPartProductRefundVoList(Arrays
					.asList(partProductRefundVo));
			partProductRefundGoodsReq.setOrderId(orderId);
			partProductRefundGoodsReq.setRemark("部分退货退款");
			partProductRefundGoodsReq.setLiabilityType(1);
			partProductRefundGoodsReq.setRefundExtType(3);
			partProductRefundGoodsReq.setRefundReasonCode(-1);
			partProductRefundGoodsReq.setHasRefundGoods(false);

			partProductRefundGoodsCall.setData(partProductRefundGoodsReq);
			partProductRefundGoodsCall.callService();

			for (RefundBill refundBill : refundBillWrapper
					.selectByOrderId(orderId)) {

				String refundNo = refundBill.getRefund_no();

				// 审核地址
				RefundService.auditRefundGoods(autotest_goodsOwnerId,
						autotest_goodsOwnerId,
						CurrentMchRefundStatusEnum.LEVEL_ONE.getCode(),
						refundNo, true);

				// 上传运单信息
				RefundService.saveOrUpdateRefundGoodsExpressInfoList(
						autotest_goodsOwnerId, refundNo, autotest_goodsOwnerId);

				// 审核运单信息
				RefundService.auditRefund(autotest_goodsOwnerId,
						autotest_goodsOwnerId,
						CurrentMchRefundStatusEnum.GOODS.getCode(), refundNo,
						true);
			}
			
			// 退款服务同步到交易
			RefundService.syncNotSyncedRefundBill();

			// 退款提交到网关
			UserRefundFundDetailPo record = new UserRefundFundDetailPo();

			Calendar calendar = Calendar.getInstance();
			calendar.setTime(new Date());
			calendar.add(Calendar.MINUTE, -6);

			record.setPaymentId(paymentId);
			record.setUpdateTime(calendar.getTime());

			orderShardingWapper.userRefundFundDetailMapper
					.updateByPrimaryKeySelective(record);

			RefundService.supplementRefund(orderId);

			// 支付网关退款回调
			SQPayGateWayCallService.refundNotifyCall("13",
					paymentId.toString(), userId.intValue());

			Thread.sleep(3000);

			this.verify(orderId);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_PartProductRefundGoods_021() {
		Logger.start(false, "代理订单，已线下付款的订单，货头申请部分退款，退款失败");
		try {

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 1, false,
							false);
			String currency = productBean.getCurrency();
			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeOrder(productBean, BigDecimal.ZERO,
							autotest_goodsOwnerId, currency, true);

			Order order = placeOrderResp.getOrderList().get(0);

			long orderId = order.getOrderId();
			Long userId = placeOrderResp.getUserId();

			// 支付线下支付订单
			SqTradingCallService.payOrder(userId,
					placeOrderResp.getTradingId(), "wxsqBuyer", "200");
			SqTradingCallService.confirmOfflinePay(orderId,
					autotest_goodsOwnerId);

			Thread.sleep(5000);

			// 接单
			SqTradingCallService.sellerAcceptOrder(autotest_goodsOwnerId,
					orderId);

			// 发货
			SqTradingCallService.delivery(autotest_goodsOwnerId, orderId,
					null, null);

			OrderDetailPo orderDetailPo = placeOrderResp.getOrderList().get(0)
					.getOrderDetailPoList().get(0);

			PartProductRefundVo partProductRefundVo = RefundService
					.buildPartProductRefundVo(orderDetailPo.getCatalogId(),
							BigDecimal.ONE, BigDecimal.ONE, BigDecimal.ONE,
							orderDetailPo.getProductCount());

			partProductRefundGoodsReq.setUserId(autotest_goodsOwnerId);
			partProductRefundGoodsReq.setCsId(1234L);
			partProductRefundGoodsReq.setPartProductRefundVoList(Arrays
					.asList(partProductRefundVo));
			partProductRefundGoodsReq.setOrderId(orderId);
			partProductRefundGoodsReq.setRemark("部分退货退款");
			partProductRefundGoodsReq.setLiabilityType(1);
			partProductRefundGoodsReq.setRefundExtType(3);
			partProductRefundGoodsReq.setRefundReasonCode(-1);
			partProductRefundGoodsReq.setHasRefundGoods(false);

			partProductRefundGoodsCall.setData(partProductRefundGoodsReq);
			partProductRefundGoodsCall.callService();

			Logger.verifyEquals("线下支付订单，不能退货退款",
					partProductRefundGoodsCall.getMsg(), "验证resultMessage");
			Logger.verifyEquals("3", partProductRefundGoodsCall.getCode(),
					"验证resultCode");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_PartProductRefundGoods_022() {
		Logger.start(false, "直销订单多个商品，已发货，货头申请部分退货退款，某个商品全部退款");
		try {

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 0, false,
							false);

			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeOrderWithMultiProsInOneOrder(productBean,
							new BigDecimal("0.15"));

			Order order = placeOrderResp.getOrderList().get(0);

			long sellerId = order.getSellerId();
			Long userId = placeOrderResp.getUserId();

			long orderId = order.getOrderId();

			BigDecimal amount = placeOrderResp.getPayableAmount();

			SqTradingMqService.updateLiveOrder(false, orderId);

			// 支付订单
			Long thirdTradingId = SqTradingCallService.payOrder(userId,
					placeOrderResp.getTradingId());

			// 支付网关支付回调交易
			SQPayGateWayCallService.DGSQNotifyCall(
					String.valueOf(thirdTradingId),
					amount.subtract(BigDecimal.ZERO).toString(),
					userId.intValue(), BigDecimal.ZERO.toPlainString());

			Thread.sleep(5000);

			Long paymentId = orderShardingWapper.selectOrderbyOrderId(orderId)
					.getPaymentId();

			PaymentPo payment = orderShardingWapper
					.selectPaymentById(paymentId);

			ShenqiSettlementService.onHpSettled(paymentId, payment, null, 1);

			// 卖家接单
			SqTradingCallService.sellerAcceptOrder(sellerId, orderId);

			// 发货
			SqTradingCallService.delivery(autotest_goodsOwnerId, orderId,
					null, null);

			OrderDetailPo orderDetailPo = placeOrderResp.getOrderList().get(0)
					.getOrderDetailPoList().get(0);

			int refundCount = orderDetailPo.getProductCount();

			BigDecimal refundFreight = RefundService.getMaxCanRefundFreight(
					orderDetailPo, orderDetailPo.getFreight());
			BigDecimal refundProductAmount = RefundService
					.getOrderDetailPaidAmountExcludeFreight(orderDetailPo,
							refundCount, false);
			BigDecimal taxFeeAmount = RefundService.getOrderDetailTaxFeeAmount(
					orderDetailPo, refundCount);

			PartProductRefundVo partProductRefundVo = RefundService
					.buildPartProductRefundVo(orderDetailPo.getCatalogId(),
							refundFreight, refundProductAmount, taxFeeAmount,
							refundCount);

			partProductRefundGoodsReq.setUserId(autotest_goodsOwnerId);
			partProductRefundGoodsReq.setCsId(1234L);
			partProductRefundGoodsReq.setPartProductRefundVoList(Arrays
					.asList(partProductRefundVo));
			partProductRefundGoodsReq.setOrderId(orderId);
			partProductRefundGoodsReq.setRemark("部分退货退款");
			partProductRefundGoodsReq.setLiabilityType(1);
			partProductRefundGoodsReq.setRefundExtType(3);
			partProductRefundGoodsReq.setRefundReasonCode(-1);
			partProductRefundGoodsReq.setHasRefundGoods(false);

			partProductRefundGoodsCall.setData(partProductRefundGoodsReq);
			partProductRefundGoodsCall.callService();

			for (RefundBill refundBill : refundBillWrapper
					.selectByOrderId(orderId)) {

				String refundNo = refundBill.getRefund_no();

				// 审核地址
				RefundService.auditRefundGoods(autotest_goodsOwnerId,
						autotest_goodsOwnerId,
						CurrentMchRefundStatusEnum.LEVEL_ONE.getCode(),
						refundNo, true);

				// 上传运单信息
				RefundService.saveOrUpdateRefundGoodsExpressInfoList(
						autotest_goodsOwnerId, refundNo, autotest_goodsOwnerId);

				// 审核运单信息
				RefundService.auditRefund(autotest_goodsOwnerId,
						autotest_goodsOwnerId,
						CurrentMchRefundStatusEnum.GOODS.getCode(), refundNo,
						true);
			}

			// 退款服务同步到交易
			RefundService.syncNotSyncedRefundBill();

			// 退款提交到网关
			UserRefundFundDetailPo record = new UserRefundFundDetailPo();

			Calendar calendar = Calendar.getInstance();
			calendar.setTime(new Date());
			calendar.add(Calendar.MINUTE, -6);

			record.setPaymentId(paymentId);
			record.setUpdateTime(calendar.getTime());

			orderShardingWapper.userRefundFundDetailMapper
					.updateByPrimaryKeySelective(record);

			RefundService.supplementRefund(orderId);

			// 支付网关退款回调
			SQPayGateWayCallService.refundNotifyCall("13",
					paymentId.toString(), userId.intValue());

			Thread.sleep(3000);

			this.verify(orderId);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_PartProductRefundGoods_023() {
		Logger.start(false, "直销订单多个商品，已发货，仅退款剩下0.01，继续申请部分退货退款，直至所有商品全部退完");
		try {

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 0, false,
							false);

			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeOrderWithMultiProsInOneOrder(productBean,
							new BigDecimal("0.15"));

			Order order = placeOrderResp.getOrderList().get(0);

			long sellerId = order.getSellerId();
			Long userId = placeOrderResp.getUserId();

			long orderId = order.getOrderId();

			BigDecimal amount = placeOrderResp.getPayableAmount();

			SqTradingMqService.updateLiveOrder(false, orderId);

			// 支付订单
			Long thirdTradingId = SqTradingCallService.payOrder(userId,
					placeOrderResp.getTradingId());

			// 支付网关支付回调交易
			SQPayGateWayCallService.DGSQNotifyCall(
					String.valueOf(thirdTradingId),
					amount.subtract(BigDecimal.ZERO).toString(),
					userId.intValue(), BigDecimal.ZERO.toPlainString());

			Thread.sleep(5000);

			Long paymentId = orderShardingWapper.selectOrderbyOrderId(orderId)
					.getPaymentId();

			PaymentPo payment = orderShardingWapper
					.selectPaymentById(paymentId);

			ShenqiSettlementService.onHpSettled(paymentId, payment, null, 1);

			// 卖家接单
			SqTradingCallService.sellerAcceptOrder(sellerId, orderId);

			// 发货
			SqTradingCallService.delivery(autotest_goodsOwnerId, orderId,
					null, null);

			BigDecimal orderMaxRefundAmount = RefundService
					.getOrderMaxRefundAmount(order);
			String refundedBillNo = RefundService
					.createPartAmountRefundSuccess(orderId,
							autotest_goodsOwnerId, paymentId, userId,
							orderMaxRefundAmount
									.subtract(new BigDecimal("0.01")));

			OrderDetailPo remainOrderDetailPo = null;

			for (OrderDetailPo orderDetailPo : placeOrderResp.getOrderList()
					.get(0).getOrderDetailPoList()) {

				BigDecimal remainAmount = RefundService
						.getOrderDetailPoMaxRefundAmount(orderId,
								orderDetailPo, orderDetailPo.getProductCount());

				if (remainAmount.compareTo(BigDecimal.ZERO) == 1)
					remainOrderDetailPo = orderDetailPo;
			}

			int refundCount = remainOrderDetailPo.getProductCount();

			BigDecimal refundFreight = RefundService.getMaxCanRefundFreight(
					remainOrderDetailPo, remainOrderDetailPo.getFreight());
			BigDecimal refundProductAmount = new BigDecimal("0.01");
			BigDecimal taxFeeAmount = RefundService.getOrderDetailTaxFeeAmount(
					remainOrderDetailPo, refundCount);

			PartProductRefundVo partProductRefundVo = RefundService
					.buildPartProductRefundVo(
							remainOrderDetailPo.getCatalogId(), refundFreight,
							refundProductAmount, taxFeeAmount, refundCount);

			partProductRefundGoodsReq.setUserId(autotest_goodsOwnerId);
			partProductRefundGoodsReq.setCsId(1234L);
			partProductRefundGoodsReq.setPartProductRefundVoList(Arrays
					.asList(partProductRefundVo));
			partProductRefundGoodsReq.setOrderId(orderId);
			partProductRefundGoodsReq.setRemark("部分退货退款");
			partProductRefundGoodsReq.setLiabilityType(1);
			partProductRefundGoodsReq.setRefundExtType(3);
			partProductRefundGoodsReq.setRefundReasonCode(-1);
			partProductRefundGoodsReq.setHasRefundGoods(false);

			partProductRefundGoodsCall.setData(partProductRefundGoodsReq);
			partProductRefundGoodsCall.callService();

			for (RefundBill refundBill : refundBillWrapper
					.selectByOrderId(orderId)) {

				String refundNo = refundBill.getRefund_no();

				// 审核地址
				RefundService.auditRefundGoods(autotest_goodsOwnerId,
						autotest_goodsOwnerId,
						CurrentMchRefundStatusEnum.LEVEL_ONE.getCode(),
						refundNo, true);

				// 上传运单信息
				RefundService.saveOrUpdateRefundGoodsExpressInfoList(
						autotest_goodsOwnerId, refundNo, autotest_goodsOwnerId);

				// 审核运单信息
				RefundService.auditRefund(autotest_goodsOwnerId,
						autotest_goodsOwnerId,
						CurrentMchRefundStatusEnum.GOODS.getCode(), refundNo,
						true);
			}

			// 退款服务同步到交易
			RefundService.syncNotSyncedRefundBill();

			// 退款提交到网关
			UserRefundFundDetailPo record = new UserRefundFundDetailPo();

			Calendar calendar = Calendar.getInstance();
			calendar.setTime(new Date());
			calendar.add(Calendar.MINUTE, -6);

			record.setPaymentId(paymentId);
			record.setUpdateTime(calendar.getTime());

			orderShardingWapper.userRefundFundDetailMapper
					.updateByPrimaryKeySelective(record);

			RefundService.supplementRefund(orderId);

			// 支付网关退款回调
			SQPayGateWayCallService.refundNotifyCall("13",
					paymentId.toString(), userId.intValue());

			Thread.sleep(3000);

			this.verify(orderId, Arrays.asList(refundedBillNo));

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_PartProductRefundGoods_024() {
		Logger.start(false, "直销订单，申请的商品金额超过最大可申请金额，申请失败");
		try {

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 0, false,
							false);

			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeOrder1(productBean, autotest_goodsOwnerId);

			Order order = placeOrderResp.getOrderList().get(0);

			long sellerId = order.getSellerId();
			Long userId = placeOrderResp.getUserId();

			long orderId = order.getOrderId();

			BigDecimal amount = placeOrderResp.getPayableAmount();

			// 支付订单
			Long thirdTradingId = SqTradingCallService.payOrder(userId,
					placeOrderResp.getTradingId());

			// 支付网关支付回调交易
			SQPayGateWayCallService.DGSQNotifyCall(
					String.valueOf(thirdTradingId),
					amount.subtract(BigDecimal.ZERO).toString(),
					userId.intValue(), BigDecimal.ZERO.toPlainString());

			Thread.sleep(5000);

			// 卖家接单
			SqTradingCallService.sellerAcceptOrder(sellerId, orderId);

			// 发货
			SqTradingCallService.delivery(autotest_goodsOwnerId, orderId,
					null, null);

			OrderDetailPo orderDetailPo = placeOrderResp.getOrderList().get(0)
					.getOrderDetailPoList().get(0);

			int refundCount = orderDetailPo.getProductCount();
			BigDecimal maxRefundProdAmount = RefundService
					.getOrderDetailPaidAmountExcludeFreight(orderDetailPo,
							refundCount, false);

			PartProductRefundVo partProductRefundVo = RefundService
					.buildPartProductRefundVo(orderDetailPo.getCatalogId(),
							BigDecimal.ONE,
							maxRefundProdAmount.add(new BigDecimal("0.01")),
							BigDecimal.ZERO, 1);

			partProductRefundGoodsReq.setUserId(autotest_goodsOwnerId);
			partProductRefundGoodsReq.setCsId(1234L);
			partProductRefundGoodsReq.setPartProductRefundVoList(Arrays
					.asList(partProductRefundVo));
			partProductRefundGoodsReq.setOrderId(orderId);
			partProductRefundGoodsReq.setRemark("部分退货退款");
			partProductRefundGoodsReq.setLiabilityType(1);
			partProductRefundGoodsReq.setRefundExtType(3);
			partProductRefundGoodsReq.setRefundReasonCode(-1);
			partProductRefundGoodsReq.setHasRefundGoods(false);

			partProductRefundGoodsCall.setData(partProductRefundGoodsReq);
			partProductRefundGoodsCall.callService();

			Logger.verifyEquals(
					String.format("规格：%s退款金额大于可退金额",
							orderDetailPo.getCatalogId()),
					partProductRefundGoodsCall.getMsg(), "验证resultMessage");
			Logger.verifyEquals("3", partProductRefundGoodsCall.getCode(),
					"验证resultCode");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_PartProductRefundGoods_025() {
		Logger.start(false, "直销订单，申请的运费超过最大可申请运费，申请失败");
		try {

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 0, false,
							false);

			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeOrder1(productBean, autotest_goodsOwnerId);

			Order order = placeOrderResp.getOrderList().get(0);

			long sellerId = order.getSellerId();
			Long userId = placeOrderResp.getUserId();

			long orderId = order.getOrderId();

			BigDecimal amount = placeOrderResp.getPayableAmount();

			// 支付订单
			Long thirdTradingId = SqTradingCallService.payOrder(userId,
					placeOrderResp.getTradingId());

			// 支付网关支付回调交易
			SQPayGateWayCallService.DGSQNotifyCall(
					String.valueOf(thirdTradingId),
					amount.subtract(BigDecimal.ZERO).toString(),
					userId.intValue(), BigDecimal.ZERO.toPlainString());

			Thread.sleep(5000);

			// 卖家接单
			SqTradingCallService.sellerAcceptOrder(sellerId, orderId);

			// 发货
			SqTradingCallService.delivery(autotest_goodsOwnerId, orderId,
					null, null);

			OrderDetailPo orderDetailPo = placeOrderResp.getOrderList().get(0)
					.getOrderDetailPoList().get(0);

			int refundCount = orderDetailPo.getProductCount();
			BigDecimal maxRefundProdAmount = RefundService
					.getOrderDetailPaidAmountExcludeFreight(orderDetailPo,
							refundCount, false);

			PartProductRefundVo partProductRefundVo = RefundService
					.buildPartProductRefundVo(orderDetailPo.getCatalogId(),
							orderDetailPo.getFreight().add(BigDecimal.ONE),
							maxRefundProdAmount, BigDecimal.ZERO, 1);

			partProductRefundGoodsReq.setUserId(autotest_goodsOwnerId);
			partProductRefundGoodsReq.setCsId(1234L);
			partProductRefundGoodsReq.setPartProductRefundVoList(Arrays
					.asList(partProductRefundVo));
			partProductRefundGoodsReq.setOrderId(orderId);
			partProductRefundGoodsReq.setRemark("部分退货退款");
			partProductRefundGoodsReq.setLiabilityType(1);
			partProductRefundGoodsReq.setRefundExtType(3);
			partProductRefundGoodsReq.setRefundReasonCode(-1);
			partProductRefundGoodsReq.setHasRefundGoods(false);

			partProductRefundGoodsCall.setData(partProductRefundGoodsReq);
			partProductRefundGoodsCall.callService();

			Logger.verifyEquals(
					String.format("规格：%s退款金额大于可退金额",
							orderDetailPo.getCatalogId()),
					partProductRefundGoodsCall.getMsg(), "验证resultMessage");
			Logger.verifyEquals("3", partProductRefundGoodsCall.getCode(),
					"验证resultCode");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_PartProductRefundGoods_026() {
		Logger.start(false, "直销订单，申请的税费超过最大可申请税费，申请失败");
		try {

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 0, false,
							false);

			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeOrder1(productBean, autotest_goodsOwnerId);

			Order order = placeOrderResp.getOrderList().get(0);

			long sellerId = order.getSellerId();
			Long userId = placeOrderResp.getUserId();

			long orderId = order.getOrderId();

			BigDecimal amount = placeOrderResp.getPayableAmount();

			// 支付订单
			Long thirdTradingId = SqTradingCallService.payOrder(userId,
					placeOrderResp.getTradingId());

			// 支付网关支付回调交易
			SQPayGateWayCallService.DGSQNotifyCall(
					String.valueOf(thirdTradingId),
					amount.subtract(BigDecimal.ZERO).toString(),
					userId.intValue(), BigDecimal.ZERO.toPlainString());

			Thread.sleep(5000);

			// 卖家接单
			SqTradingCallService.sellerAcceptOrder(sellerId, orderId);

			// 发货
			SqTradingCallService.delivery(autotest_goodsOwnerId, orderId,
					null, null);

			OrderDetailPo orderDetailPo = placeOrderResp.getOrderList().get(0)
					.getOrderDetailPoList().get(0);

			int refundCount = orderDetailPo.getProductCount();

			BigDecimal maxRefundProdAmount = RefundService
					.getOrderDetailPaidAmountExcludeFreight(orderDetailPo,
							refundCount, false);
			BigDecimal maxRefundTaxFeeAmount = RefundService
					.getOrderDetailTaxFeeAmount(orderDetailPo, refundCount);

			PartProductRefundVo partProductRefundVo = RefundService
					.buildPartProductRefundVo(orderDetailPo.getCatalogId(),
							orderDetailPo.getFreight(), maxRefundProdAmount,
							maxRefundTaxFeeAmount.add(BigDecimal.ONE), 1);

			partProductRefundGoodsReq.setUserId(autotest_goodsOwnerId);
			partProductRefundGoodsReq.setCsId(1234L);
			partProductRefundGoodsReq.setPartProductRefundVoList(Arrays
					.asList(partProductRefundVo));
			partProductRefundGoodsReq.setOrderId(orderId);
			partProductRefundGoodsReq.setRemark("部分退货退款");
			partProductRefundGoodsReq.setLiabilityType(1);
			partProductRefundGoodsReq.setRefundExtType(3);
			partProductRefundGoodsReq.setRefundReasonCode(-1);
			partProductRefundGoodsReq.setHasRefundGoods(false);

			partProductRefundGoodsCall.setData(partProductRefundGoodsReq);
			partProductRefundGoodsCall.callService();

			Logger.verifyEquals(
					String.format("规格：%s退款金额大于可退金额",
							orderDetailPo.getCatalogId()),
					partProductRefundGoodsCall.getMsg(), "验证resultMessage");
			Logger.verifyEquals("3", partProductRefundGoodsCall.getCode(),
					"验证resultCode");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_PartProductRefundGoods_027() {
		Logger.start(false, "代理订单，已发货，货头申请部分退款，修改商品退款金额，退款失败");
		try {

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 1, false,
							false);

			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeOrder1(productBean, autotest_goodsOwnerId);

			Order order = placeOrderResp.getOrderList().get(0);

			Long userId = placeOrderResp.getUserId();

			long orderId = order.getOrderId();

			BigDecimal amount = placeOrderResp.getPayableAmount();

			// 支付订单
			Long thirdTradingId = SqTradingCallService.payOrder(userId,
					placeOrderResp.getTradingId());

			// 支付网关支付回调交易
			SQPayGateWayCallService.DGSQNotifyCall(
					String.valueOf(thirdTradingId),
					amount.subtract(BigDecimal.ZERO).toString(),
					userId.intValue(), BigDecimal.ZERO.toPlainString());

			Thread.sleep(5000);

			OrderDetailPo orderDetailPo = placeOrderResp.getOrderList().get(0)
					.getOrderDetailPoList().get(0);

			PartProductRefundVo partProductRefundVo = RefundService
					.buildPartProductRefundVo(orderDetailPo.getCatalogId(),
							BigDecimal.ZERO, BigDecimal.ONE, BigDecimal.ZERO, 1);

			// 卖家接单
			SqTradingCallService.sellerAcceptOrder(autotest_goodsOwnerId,
					orderId);

			// 发货
			SqTradingCallService.delivery(autotest_goodsOwnerId, orderId,
					null, null);

			partProductRefundGoodsReq.setUserId(autotest_goodsOwnerId);
			partProductRefundGoodsReq.setCsId(1234L);
			partProductRefundGoodsReq.setPartProductRefundVoList(Arrays
					.asList(partProductRefundVo));
			partProductRefundGoodsReq.setOrderId(orderId);
			partProductRefundGoodsReq.setRemark("部分退货退款");
			partProductRefundGoodsReq.setLiabilityType(1);
			partProductRefundGoodsReq.setRefundExtType(3);
			partProductRefundGoodsReq.setRefundReasonCode(-1);
			partProductRefundGoodsReq.setHasRefundGoods(false);

			partProductRefundGoodsCall.setData(partProductRefundGoodsReq);
			partProductRefundGoodsCall.callService();

			Logger.verifyEquals("代理订单退款商品金额不正确",
					partProductRefundGoodsCall.getMsg(), "验证resultMessage");
			Logger.verifyEquals("3", partProductRefundGoodsCall.getCode(),
					"验证resultCode");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_PartProductRefundGoods_028() {
		Logger.start(false, "直销订单，已经部分退款成功的商品，再次部分退货退款，退款失败");
		try {

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 0, false,
							false);

			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeOrder1(productBean, autotest_goodsOwnerId);

			Order order = placeOrderResp.getOrderList().get(0);

			long sellerId = order.getSellerId();
			Long userId = placeOrderResp.getUserId();

			long orderId = order.getOrderId();

			BigDecimal amount = placeOrderResp.getPayableAmount();

			SqTradingMqService.updateLiveOrder(false, orderId);

			// 支付订单
			Long thirdTradingId = SqTradingCallService.payOrder(userId,
					placeOrderResp.getTradingId());

			// 支付网关支付回调交易
			SQPayGateWayCallService.DGSQNotifyCall(
					String.valueOf(thirdTradingId),
					amount.subtract(BigDecimal.ZERO).toString(),
					userId.intValue(), BigDecimal.ZERO.toPlainString());

			Thread.sleep(5000);

			Long paymentId = orderShardingWapper.selectOrderbyOrderId(orderId)
					.getPaymentId();

			PaymentPo payment = orderShardingWapper
					.selectPaymentById(paymentId);

			ShenqiSettlementService.onHpSettled(paymentId, payment, null, 1);

			// 卖家接单
			SqTradingCallService.sellerAcceptOrder(sellerId, orderId);

			// 发货
			SqTradingCallService.delivery(autotest_goodsOwnerId, orderId,
					null, null);

			OrderDetailPo orderDetailPo = placeOrderResp.getOrderList().get(0)
					.getOrderDetailPoList().get(0);

			// 创建一个部分退货退款成功的退款单
			RefundService.createPartProductRefundSuccess(orderId,
					orderDetailPo, autotest_goodsOwnerId, paymentId, userId);

			PartProductRefundVo partProductRefundVo = RefundService
					.buildPartProductRefundVo(orderDetailPo.getCatalogId(),
							BigDecimal.ONE, BigDecimal.ONE, BigDecimal.ONE, 1);

			partProductRefundGoodsReq.setUserId(autotest_goodsOwnerId);
			partProductRefundGoodsReq.setCsId(1234L);
			partProductRefundGoodsReq.setPartProductRefundVoList(Arrays
					.asList(partProductRefundVo));
			partProductRefundGoodsReq.setOrderId(orderId);
			partProductRefundGoodsReq.setRemark("部分退货退款");
			partProductRefundGoodsReq.setLiabilityType(1);
			partProductRefundGoodsReq.setRefundExtType(3);
			partProductRefundGoodsReq.setRefundReasonCode(-1);
			partProductRefundGoodsReq.setHasRefundGoods(false);

			partProductRefundGoodsCall.setData(partProductRefundGoodsReq);
			partProductRefundGoodsCall.callService();

			Logger.verifyEquals("没有可以退的商品",
					partProductRefundGoodsCall.getMsg(), "验证resultMessage");
			Logger.verifyEquals("3", partProductRefundGoodsCall.getCode(),
					"验证resultCode");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_PartProductRefundGoods_029() {
		Logger.start(false, "直销订单，满减包邮商品，申请退运费，申请失败");
		try {

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 0, false,
							false);

			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeOrderWithFreeFreight(productBean, true);

			Order order = placeOrderResp.getOrderList().get(0);

			long sellerId = order.getSellerId();
			Long userId = placeOrderResp.getUserId();

			long orderId = order.getOrderId();

			BigDecimal amount = placeOrderResp.getPayableAmount();

			// 支付订单
			Long thirdTradingId = SqTradingCallService.payOrder(userId,
					placeOrderResp.getTradingId());

			// 支付网关支付回调交易
			SQPayGateWayCallService.DGSQNotifyCall(
					String.valueOf(thirdTradingId),
					amount.subtract(BigDecimal.ZERO).toString(),
					userId.intValue(), BigDecimal.ZERO.toPlainString());

			Thread.sleep(5000);

			// 卖家接单
			SqTradingCallService.sellerAcceptOrder(sellerId, orderId);

			// 发货
			SqTradingCallService.delivery(autotest_goodsOwnerId, orderId,
					null, null);

			OrderDetailPo orderDetailPo = placeOrderResp.getOrderList().get(0)
					.getOrderDetailPoList().get(0);

			BigDecimal maxRefundProdAmount = RefundService
					.getOrderDetailPaidAmountExcludeFreight(orderDetailPo, 1,
							false);

			PartProductRefundVo partProductRefundVo = RefundService
					.buildPartProductRefundVo(orderDetailPo.getCatalogId(),
							BigDecimal.ONE, maxRefundProdAmount,
							BigDecimal.ZERO, 1);

			partProductRefundGoodsReq.setUserId(autotest_goodsOwnerId);
			partProductRefundGoodsReq.setCsId(1234L);
			partProductRefundGoodsReq.setPartProductRefundVoList(Arrays
					.asList(partProductRefundVo));
			partProductRefundGoodsReq.setOrderId(orderId);
			partProductRefundGoodsReq.setRemark("部分退货退款");
			partProductRefundGoodsReq.setLiabilityType(1);
			partProductRefundGoodsReq.setRefundExtType(3);
			partProductRefundGoodsReq.setRefundReasonCode(-1);
			partProductRefundGoodsReq.setHasRefundGoods(false);

			partProductRefundGoodsCall.setData(partProductRefundGoodsReq);
			partProductRefundGoodsCall.callService();

			Logger.verifyEquals(
					String.format("规格：%s退款金额大于可退金额",
							orderDetailPo.getCatalogId()),
					partProductRefundGoodsCall.getMsg(), "验证resultMessage");
			Logger.verifyEquals("3", partProductRefundGoodsCall.getCode(),
					"验证resultCode");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_PartProductRefundGoods_030() {
		Logger.start(false, "直销订单，带有各种优惠，货头申请部分退货退款，退一件商品");
		try {

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 0, false,
							false);

			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeOrderWithAllPromotion(productBean, BigDecimal.TEN,
							autotest_goodsOwnerId);

			Order order = placeOrderResp.getOrderList().get(0);

			long sellerId = order.getSellerId();
			Long userId = placeOrderResp.getUserId();

			long orderId = order.getOrderId();

			BigDecimal amount = placeOrderResp.getPayableAmount();

			SqTradingMqService.updateLiveOrder(false, orderId);

			// 支付订单
			Long thirdTradingId = SqTradingCallService.payOrder(userId,
					placeOrderResp.getTradingId());

			// 支付网关支付回调交易
			SQPayGateWayCallService.DGSQNotifyCall(
					String.valueOf(thirdTradingId),
					amount.subtract(BigDecimal.ZERO).toString(),
					userId.intValue(), BigDecimal.ZERO.toPlainString());

			Thread.sleep(5000);

			Long paymentId = orderShardingWapper.selectOrderbyOrderId(orderId)
					.getPaymentId();

			PaymentPo payment = orderShardingWapper
					.selectPaymentById(paymentId);

			ShenqiSettlementService.onHpSettled(paymentId, payment, null, 1);

			// 卖家接单
			SqTradingCallService.sellerAcceptOrder(sellerId, orderId);

			// 发货
			SqTradingCallService.delivery(autotest_goodsOwnerId, orderId,
					null, null);

			OrderDetailPo orderDetailPo = placeOrderResp.getOrderList().get(0)
					.getOrderDetailPoList().get(0);

			BigDecimal maxRefundProdAmount = RefundService
					.getOrderDetailPaidAmountExcludeFreight(orderDetailPo, 1,
							false);

			PartProductRefundVo partProductRefundVo = RefundService
					.buildPartProductRefundVo(orderDetailPo.getCatalogId(),
							BigDecimal.ZERO, maxRefundProdAmount,
							BigDecimal.ZERO, 1);

			partProductRefundGoodsReq.setUserId(autotest_goodsOwnerId);
			partProductRefundGoodsReq.setCsId(1234L);
			partProductRefundGoodsReq.setPartProductRefundVoList(Arrays
					.asList(partProductRefundVo));
			partProductRefundGoodsReq.setOrderId(orderId);
			partProductRefundGoodsReq.setRemark("部分退货退款");
			partProductRefundGoodsReq.setLiabilityType(1);
			partProductRefundGoodsReq.setRefundExtType(3);
			partProductRefundGoodsReq.setRefundReasonCode(-1);
			partProductRefundGoodsReq.setHasRefundGoods(false);

			partProductRefundGoodsCall.setData(partProductRefundGoodsReq);
			partProductRefundGoodsCall.callService();

			for (RefundBill refundBill : refundBillWrapper
					.selectByOrderId(orderId)) {

				String refundNo = refundBill.getRefund_no();

				// 审核地址
				RefundService.auditRefundGoods(autotest_goodsOwnerId,
						autotest_goodsOwnerId,
						CurrentMchRefundStatusEnum.LEVEL_ONE.getCode(),
						refundNo, true);

				// 上传运单信息
				RefundService.saveOrUpdateRefundGoodsExpressInfoList(
						autotest_goodsOwnerId, refundNo, autotest_goodsOwnerId);

				// 审核运单信息
				RefundService.auditRefund(autotest_goodsOwnerId,
						autotest_goodsOwnerId,
						CurrentMchRefundStatusEnum.GOODS.getCode(), refundNo,
						true);
			}

			// 退款服务同步到交易
			RefundService.syncNotSyncedRefundBill();

			// 退款提交到网关
			UserRefundFundDetailPo record = new UserRefundFundDetailPo();

			Calendar calendar = Calendar.getInstance();
			calendar.setTime(new Date());
			calendar.add(Calendar.MINUTE, -6);

			record.setPaymentId(paymentId);
			record.setUpdateTime(calendar.getTime());

			orderShardingWapper.userRefundFundDetailMapper
					.updateByPrimaryKeySelective(record);

			RefundService.supplementRefund(orderId);

			// 支付网关退款回调
			SQPayGateWayCallService.refundNotifyCall("13",
					paymentId.toString(), userId.intValue());

			Thread.sleep(3000);

			this.verify(orderId);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_PartProductRefundGoods_031() {
		Logger.start(false, "代理订单，使用积分，已发货，货头申请部分退货退款");
		try {

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 1, false,
							false);

			Long shopId = productBean.getSellerId();

			GodPointsService.saveCreditPolicyReq((long) shopId);
			Thread.sleep(500);

			GodPointsService.sendCredit((long) shopId, 20238699L);
			Thread.sleep(500);

			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeOrderWithIntegral(productBean, autotest_goodsOwnerId,
							20L);

			Order order = placeOrderResp.getOrderList().get(0);
			Long userId = placeOrderResp.getUserId();

			long orderId = order.getOrderId();

			BigDecimal amount = placeOrderResp.getPayableAmount();

			// 支付订单
			Long thirdTradingId = SqTradingCallService.payOrder(userId,
					placeOrderResp.getTradingId());

			SqTradingMqService.updateLiveOrder(false, orderId);

			// 支付网关支付回调交易
			SQPayGateWayCallService.DGSQNotifyCall(
					String.valueOf(thirdTradingId),
					amount.subtract(BigDecimal.ZERO).toString(),
					userId.intValue(), BigDecimal.ZERO.toPlainString());

			Thread.sleep(5000);

			Long paymentId = orderShardingWapper.selectOrderbyOrderId(orderId)
					.getPaymentId();

			PaymentPo payment = orderShardingWapper
					.selectPaymentById(paymentId);

			ShenqiSettlementService.onHpSettled(paymentId, payment, null, 1);

			// 卖家接单
			SqTradingCallService.sellerAcceptOrder(autotest_goodsOwnerId,
					orderId);

			// 发货
			SqTradingCallService.delivery(autotest_goodsOwnerId, orderId,
					null, null);

			OrderDetailPo orderDetailPo = placeOrderResp.getOrderList().get(0)
					.getOrderDetailPoList().get(0);

			int refundCount = 1;

			BigDecimal refundTaxAmount = RefundService
					.getOrderDetailTaxFeeAmount(orderDetailPo, refundCount);
			BigDecimal refundProductAmount = RefundService
					.getOrderDetailPaidAmountExcludeFreight(orderDetailPo,
							refundCount, false);
			BigDecimal refundFreightAmount = RefundService
					.getMaxCanRefundFreight(orderDetailPo,
							orderDetailPo.getFreight());

			PartProductRefundVo partProductRefundVo = RefundService
					.buildPartProductRefundVo(orderDetailPo.getCatalogId(),
							refundFreightAmount, refundProductAmount,
							refundTaxAmount, refundCount);

			partProductRefundGoodsReq.setUserId(autotest_goodsOwnerId);
			partProductRefundGoodsReq.setCsId(1234L);
			partProductRefundGoodsReq.setPartProductRefundVoList(Arrays
					.asList(partProductRefundVo));
			partProductRefundGoodsReq.setOrderId(orderId);
			partProductRefundGoodsReq.setRemark("部分退货退款");
			partProductRefundGoodsReq.setLiabilityType(1);
			partProductRefundGoodsReq.setRefundExtType(3);
			partProductRefundGoodsReq.setRefundReasonCode(-1);
			partProductRefundGoodsReq.setHasRefundGoods(false);

			partProductRefundGoodsCall.setData(partProductRefundGoodsReq);
			partProductRefundGoodsCall.callService();

			for (RefundBill refundBill : refundBillWrapper
					.selectByOrderId(orderId)) {

				String refundNo = refundBill.getRefund_no();

				// 审核地址
				RefundService.auditRefundGoods(autotest_goodsOwnerId,
						autotest_goodsOwnerId,
						CurrentMchRefundStatusEnum.LEVEL_ONE.getCode(),
						refundNo, true);

				// 上传运单信息
				RefundService.saveOrUpdateRefundGoodsExpressInfoList(
						autotest_goodsOwnerId, refundNo, autotest_goodsOwnerId);

				// 审核运单信息
				RefundService.auditRefund(autotest_goodsOwnerId,
						autotest_goodsOwnerId,
						CurrentMchRefundStatusEnum.GOODS.getCode(), refundNo,
						true);
			}

			// 退款服务同步到交易
			RefundService.syncNotSyncedRefundBill();

			// 退款提交到网关，第一次退积分
			UserRefundFundDetailPo record = new UserRefundFundDetailPo();

			Calendar calendar = Calendar.getInstance();
			calendar.setTime(new Date());
			calendar.add(Calendar.MINUTE, -6);

			record.setPaymentId(paymentId);
			record.setUpdateTime(calendar.getTime());

			orderShardingWapper.userRefundFundDetailMapper
					.updateByPrimaryKeySelective(record);

			RefundService.supplementRefund(orderId);

			Thread.sleep(5000);

			// 支付网关退款回调
			SQPayGateWayCallService.refundNotifyCall("13",
					paymentId.toString(), userId.intValue());

			Thread.sleep(3000);

			// 第二次退金额
			calendar.setTime(new Date());
			calendar.add(Calendar.HOUR, -6);

			record.setPaymentId(paymentId);
			record.setUpdateTime(calendar.getTime());

			orderShardingWapper.userRefundFundDetailMapper
					.updateByPrimaryKeySelective(record);

			RefundService.supplementRefund(orderId);

			Thread.sleep(5000);

			this.verify(orderId);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_PartProductRefundGoods_032() {
		Logger.start(false, "直销订单，使用积分，已发货，货头申请部分退货退款");
		try {

			int mchId = DGSQBaseService.createIndependenceMch("USA");

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createProxychain((int) mchId, 0, false);

			GodPointsService.saveCreditPolicyReq((long) mchId);
			Thread.sleep(500);

			GodPointsService.sendCredit((long) mchId, 20238699L);
			Thread.sleep(500);

			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeOrderWithIntegral(productBean, mchId, 20L);

			Order order = placeOrderResp.getOrderList().get(0);

			long sellerId = order.getSellerId();
			Long userId = placeOrderResp.getUserId();

			long orderId = order.getOrderId();

			BigDecimal amount = placeOrderResp.getPayableAmount();

			SqTradingMqService.updateLiveOrder(false, orderId);

			// 支付订单
			Long thirdTradingId = SqTradingCallService.payOrder(userId,
					placeOrderResp.getTradingId());

			// 支付网关支付回调交易
			SQPayGateWayCallService.DGSQNotifyCall(
					String.valueOf(thirdTradingId),
					amount.subtract(BigDecimal.ZERO).toString(),
					userId.intValue(), BigDecimal.ZERO.toPlainString());

			Thread.sleep(5000);

			Long paymentId = orderShardingWapper.selectOrderbyOrderId(orderId)
					.getPaymentId();

			PaymentPo payment = orderShardingWapper
					.selectPaymentById(paymentId);

			ShenqiSettlementService.onHpSettled(paymentId, payment, null, 1);

			// 卖家接单
			SqTradingCallService.sellerAcceptOrder(sellerId, orderId);

			// 发货
			SqTradingCallService.delivery(sellerId, orderId, null, null);

			OrderDetailPo orderDetailPo = placeOrderResp.getOrderList().get(0)
					.getOrderDetailPoList().get(0);

			int refundCount = 1;

			BigDecimal refundTaxAmount = BigDecimal.ZERO;
			BigDecimal refundProductAmount = new BigDecimal("200.00");
			BigDecimal refundFreightAmount = BigDecimal.ZERO;

			PartProductRefundVo partProductRefundVo = RefundService
					.buildPartProductRefundVo(orderDetailPo.getCatalogId(),
							refundFreightAmount, refundProductAmount,
							refundTaxAmount, refundCount);

			partProductRefundGoodsReq.setUserId((long) mchId);
			partProductRefundGoodsReq.setCsId(1234L);
			partProductRefundGoodsReq.setPartProductRefundVoList(Arrays
					.asList(partProductRefundVo));
			partProductRefundGoodsReq.setOrderId(orderId);
			partProductRefundGoodsReq.setRemark("部分退货退款");
			partProductRefundGoodsReq.setLiabilityType(1);
			partProductRefundGoodsReq.setRefundExtType(3);
			partProductRefundGoodsReq.setRefundReasonCode(-1);
			partProductRefundGoodsReq.setHasRefundGoods(false);

			partProductRefundGoodsCall.setData(partProductRefundGoodsReq);
			partProductRefundGoodsCall.callService();

			for (RefundBill refundBill : refundBillWrapper
					.selectByOrderId(orderId)) {

				String refundNo = refundBill.getRefund_no();

				// 审核地址
				RefundService.auditRefundGoods(sellerId, sellerId,
						CurrentMchRefundStatusEnum.LEVEL_ONE.getCode(),
						refundNo, true);

				// 上传运单信息
				RefundService.saveOrUpdateRefundGoodsExpressInfoList(sellerId,
						refundNo, sellerId);

				// 审核运单信息
				RefundService.auditRefund(sellerId, sellerId,
						CurrentMchRefundStatusEnum.GOODS.getCode(), refundNo,
						true);
			}

			// 退款服务同步到交易
			RefundService.syncNotSyncedRefundBill();

			// 退款提交到网关，第一次退金额
			UserRefundFundDetailPo record = new UserRefundFundDetailPo();

			Calendar calendar = Calendar.getInstance();
			calendar.setTime(new Date());
			calendar.add(Calendar.HOUR, -6);

			record.setPaymentId(paymentId);
			record.setUpdateTime(calendar.getTime());

			orderShardingWapper.userRefundFundDetailMapper
					.updateByPrimaryKeySelective(record);

			RefundService.supplementRefund(orderId);

			// 支付网关退款回调
			SQPayGateWayCallService.refundNotifyCall("13",
					paymentId.toString(), userId.intValue());

			Thread.sleep(3000);

			// 第二次退自有积分
			calendar.setTime(new Date());
			calendar.add(Calendar.HOUR, -6);

			record.setPaymentId(paymentId);
			record.setUpdateTime(calendar.getTime());

			orderShardingWapper.userRefundFundDetailMapper
					.updateByPrimaryKeySelective(record);

			RefundService.supplementRefund(orderId);

			this.verify(orderId);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_PartProductRefundGoods_033() {
		Logger.start(false, "直销订单，多个组合商品，使用积分，已发货，货头申请部分退货退款");
		try {

			int mchId = DGSQBaseService.createIndependenceMch("USA");

			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeMultiComposeProductOrderWithIntegral(mchId);

			Order order = placeOrderResp.getOrderList().get(0);

			long sellerId = order.getSellerId();
			Long userId = placeOrderResp.getUserId();

			long orderId = order.getOrderId();

			BigDecimal amount = placeOrderResp.getPayableAmount();

			SqTradingMqService.updateLiveOrder(false, orderId);

			// 支付订单
			Long thirdTradingId = SqTradingCallService.payOrder(userId,
					placeOrderResp.getTradingId());

			// 支付网关支付回调交易
			SQPayGateWayCallService.DGSQNotifyCall(
					String.valueOf(thirdTradingId),
					amount.subtract(BigDecimal.ZERO).toString(),
					userId.intValue(), BigDecimal.ZERO.toPlainString());

			Thread.sleep(5000);

			Long paymentId = orderShardingWapper.selectOrderbyOrderId(orderId)
					.getPaymentId();

			PaymentPo payment = orderShardingWapper
					.selectPaymentById(paymentId);

			ShenqiSettlementService.onHpSettled(paymentId, payment, null, 1);

			// 卖家接单
			SqTradingCallService.sellerAcceptOrder(sellerId, orderId);

			// 发货
			SqTradingCallService.delivery(sellerId, orderId, null, null);

			OrderDetailPo orderDetailPo = placeOrderResp.getOrderList().get(0)
					.getOrderDetailPoList().get(0);

			int refundCount = orderDetailPo.getProductCount();

			BigDecimal refundFreight = RefundService.getMaxCanRefundFreight(
					orderDetailPo, orderDetailPo.getFreight());
			BigDecimal refundProductAmount = RefundService
					.getOrderDetailPaidAmountExcludeFreight(orderDetailPo,
							refundCount, false);
			BigDecimal taxFeeAmount = RefundService.getOrderDetailTaxFeeAmount(
					orderDetailPo, refundCount);

			PartProductRefundVo partProductRefundVo = RefundService
					.buildPartProductRefundVo(orderDetailPo.getCatalogId(),
							refundFreight, refundProductAmount, taxFeeAmount,
							refundCount);

			partProductRefundGoodsReq.setUserId((long) mchId);
			partProductRefundGoodsReq.setCsId(1234L);
			partProductRefundGoodsReq.setPartProductRefundVoList(Arrays
					.asList(partProductRefundVo));
			partProductRefundGoodsReq.setOrderId(orderId);
			partProductRefundGoodsReq.setRemark("部分退货退款");
			partProductRefundGoodsReq.setLiabilityType(1);
			partProductRefundGoodsReq.setRefundExtType(3);
			partProductRefundGoodsReq.setRefundReasonCode(-1);
			partProductRefundGoodsReq.setHasRefundGoods(false);

			partProductRefundGoodsCall.setData(partProductRefundGoodsReq);
			partProductRefundGoodsCall.callService();

			for (RefundBill refundBill : refundBillWrapper
					.selectByOrderId(orderId)) {

				String refundNo = refundBill.getRefund_no();

				// 审核地址
				RefundService.auditRefundGoods(sellerId, sellerId,
						CurrentMchRefundStatusEnum.LEVEL_ONE.getCode(),
						refundNo, true);

				// 上传运单信息
				RefundService.saveOrUpdateRefundGoodsExpressInfoList(sellerId,
						refundNo, sellerId);

				// 审核运单信息
				RefundService.auditRefund(sellerId, sellerId,
						CurrentMchRefundStatusEnum.GOODS.getCode(), refundNo,
						true);
			}

			// 退款服务同步到交易
			RefundService.syncNotSyncedRefundBill();

			// 退款提交到网关
			UserRefundFundDetailPo record = new UserRefundFundDetailPo();

			Calendar calendar = Calendar.getInstance();
			calendar.setTime(new Date());
			calendar.add(Calendar.MINUTE, -6);

			record.setPaymentId(paymentId);
			record.setUpdateTime(calendar.getTime());

			orderShardingWapper.userRefundFundDetailMapper
					.updateByPrimaryKeySelective(record);

			RefundService.supplementRefund(orderId);

			// 支付网关退款回调
			SQPayGateWayCallService.refundNotifyCall("13",
					paymentId.toString(), userId.intValue());

			Thread.sleep(3000);

			// 第二次退自有积分
			calendar.setTime(new Date());
			calendar.add(Calendar.HOUR, -6);

			record.setPaymentId(paymentId);
			record.setUpdateTime(calendar.getTime());

			orderShardingWapper.userRefundFundDetailMapper
					.updateByPrimaryKeySelective(record);

			RefundService.supplementRefund(orderId);

			this.verify(orderId);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_PartProductRefundGoods_034() {
		Logger.start(false, "代理订单，多商品订单，使用积分，依次退货退款，退款成功");
		try {

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 1, false,
							false);

			Long shopId = productBean.getSellerId();

			GodPointsService.saveCreditPolicyReq((long) shopId);
			Thread.sleep(500);

			GodPointsService.sendCredit((long) shopId, 20238699L);
			Thread.sleep(500);

			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeOrderWithMultiProsInOneOrderWithIntegral(productBean,
							20L);

			Order order = placeOrderResp.getOrderList().get(0);

			Long userId = placeOrderResp.getUserId();

			long orderId = order.getOrderId();

			BigDecimal amount = placeOrderResp.getPayableAmount();

			SqTradingMqService.updateLiveOrder(false, orderId);

			// 支付订单
			Long thirdTradingId = SqTradingCallService.payOrder(userId,
					placeOrderResp.getTradingId());

			// 支付网关支付回调交易
			SQPayGateWayCallService.DGSQNotifyCall(
					String.valueOf(thirdTradingId),
					amount.subtract(BigDecimal.ZERO).toString(),
					userId.intValue(), BigDecimal.ZERO.toPlainString());

			Thread.sleep(5000);

			Long paymentId = orderShardingWapper.selectOrderbyOrderId(orderId)
					.getPaymentId();

			PaymentPo payment = orderShardingWapper
					.selectPaymentById(paymentId);

			ShenqiSettlementService.onHpSettled(paymentId, payment, null, 1);

			// 卖家接单
			SqTradingCallService.sellerAcceptOrder(autotest_goodsOwnerId,
					orderId);

			// 发货
			SqTradingCallService.delivery(autotest_goodsOwnerId, orderId,
					null, null);

			for (OrderDetailPo orderDetailPo : order.getOrderDetailPoList()) {

				int refundCount = orderDetailPo.getProductCount();

				BigDecimal refundTaxAmount = RefundService
						.getOrderDetailTaxFeeAmount(orderDetailPo, refundCount);
				BigDecimal refundProductAmount = RefundService
						.getOrderDetailPaidAmountExcludeFreight(orderDetailPo,
								refundCount, false);
				BigDecimal refundFreightAmount = RefundService
						.getMaxCanRefundFreight(orderDetailPo,
								orderDetailPo.getFreight());

				PartProductRefundVo partProductRefundVo = RefundService
						.buildPartProductRefundVo(orderDetailPo.getCatalogId(),
								refundFreightAmount, refundProductAmount,
								refundTaxAmount, refundCount);

				partProductRefundGoodsReq.setUserId(autotest_goodsOwnerId);
				partProductRefundGoodsReq.setCsId(1234L);
				partProductRefundGoodsReq.setPartProductRefundVoList(Arrays
						.asList(partProductRefundVo));
				partProductRefundGoodsReq.setOrderId(orderId);
				partProductRefundGoodsReq.setRemark("部分退货退款");
				partProductRefundGoodsReq.setLiabilityType(1);
				partProductRefundGoodsReq.setRefundExtType(3);
				partProductRefundGoodsReq.setRefundReasonCode(-1);
				partProductRefundGoodsReq.setHasRefundGoods(false);

				partProductRefundGoodsCall.setData(partProductRefundGoodsReq);
				partProductRefundGoodsCall.callService();

				for (RefundBill refundBill : refundBillWrapper
						.selectByOrderId(orderId)) {

					String refundNo = refundBill.getRefund_no();

					// 审核地址
					RefundService.auditRefundGoods(autotest_goodsOwnerId,
							autotest_goodsOwnerId,
							CurrentMchRefundStatusEnum.LEVEL_ONE.getCode(),
							refundNo, true);

					// 上传运单信息
					RefundService.saveOrUpdateRefundGoodsExpressInfoList(
							autotest_goodsOwnerId, refundNo, autotest_goodsOwnerId);

					// 审核运单信息
					RefundService.auditRefund(autotest_goodsOwnerId,
							autotest_goodsOwnerId,
							CurrentMchRefundStatusEnum.GOODS.getCode(),
							refundNo, true);
				}

				// 退款服务同步到交易
				RefundService.syncNotSyncedRefundBill();

				// 退款提交到网关
				UserRefundFundDetailPo record = new UserRefundFundDetailPo();

				Calendar calendar = Calendar.getInstance();
				calendar.setTime(new Date());
				calendar.add(Calendar.MINUTE, -6);

				record.setPaymentId(paymentId);
				record.setUpdateTime(calendar.getTime());

				orderShardingWapper.userRefundFundDetailMapper
						.updateByPrimaryKeySelective(record);

				RefundService.supplementRefund(orderId);

				Thread.sleep(3000);

				// 支付网关退款回调
				SQPayGateWayCallService.refundNotifyCall("13",
						paymentId.toString(), userId.intValue());

				Thread.sleep(3000);

				// 第二次退自有积分
				calendar.setTime(new Date());
				calendar.add(Calendar.HOUR, -6);

				record.setPaymentId(paymentId);
				record.setUpdateTime(calendar.getTime());

				orderShardingWapper.userRefundFundDetailMapper
						.updateByPrimaryKeySelective(record);

				RefundService.supplementRefund(orderId);

				this.verify(orderId);
			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_PartProductRefundGoods_035() {
		Logger.start(false, "直销订单多个商品，使用积分，未发货，仅退款剩下0.01，继续申请部分退货退款，直至所有商品全部退完");
		try {

			int mchId = DGSQBaseService.createIndependenceMch("USA");

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createProxychain((int) mchId, 0, false);

			GodPointsService.saveCreditPolicyReq((long) mchId);
			Thread.sleep(500);

			GodPointsService.sendCredit((long) mchId, 20238699L);
			Thread.sleep(500);

			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeOrderWithMultiProsInOneOrderWithIntegral(productBean,
							20L);

			Order order = placeOrderResp.getOrderList().get(0);

			long sellerId = order.getSellerId();
			Long userId = placeOrderResp.getUserId();

			long orderId = order.getOrderId();

			BigDecimal amount = placeOrderResp.getPayableAmount();

			SqTradingMqService.updateLiveOrder(false, orderId);

			// 支付订单
			Long thirdTradingId = SqTradingCallService.payOrder(userId,
					placeOrderResp.getTradingId());

			// 支付网关支付回调交易
			SQPayGateWayCallService.DGSQNotifyCall(
					String.valueOf(thirdTradingId),
					amount.subtract(BigDecimal.ZERO).toString(),
					userId.intValue(), BigDecimal.ZERO.toPlainString());

			Thread.sleep(5000);

			Long paymentId = orderShardingWapper.selectOrderbyOrderId(orderId)
					.getPaymentId();

			PaymentPo payment = orderShardingWapper
					.selectPaymentById(paymentId);

			ShenqiSettlementService.onHpSettled(paymentId, payment, null, 1);

			// 卖家接单
			SqTradingCallService.sellerAcceptOrder(sellerId, orderId);

			// 发货
			SqTradingCallService.delivery(sellerId, orderId, null, null);

			BigDecimal orderMaxRefundAmount = RefundService
					.getOrderMaxRefundAmount(order);
			String refundedBillNo = RefundService
					.createPartAmountRefundSuccess(orderId, (long) mchId,
							paymentId, userId, orderMaxRefundAmount
									.subtract(new BigDecimal("0.01")));

			OrderDetailPo remainOrderDetailPo = null;

			for (OrderDetailPo orderDetailPo : placeOrderResp.getOrderList()
					.get(0).getOrderDetailPoList()) {

				BigDecimal remainAmount = RefundService
						.getOrderDetailPoMaxRefundAmount(orderId,
								orderDetailPo, orderDetailPo.getProductCount());

				if (remainAmount.compareTo(BigDecimal.ZERO) == 1)
					remainOrderDetailPo = orderDetailPo;
			}

			int refundCount = remainOrderDetailPo.getProductCount();

			BigDecimal refundFreight = order.getOrderFreight();
			BigDecimal refundProductAmount = new BigDecimal("0.01");
			BigDecimal taxFeeAmount = RefundService.getOrderDetailTaxFeeAmount(
					remainOrderDetailPo, refundCount);

			PartProductRefundVo partProductRefundVo = RefundService
					.buildPartProductRefundVo(
							remainOrderDetailPo.getCatalogId(), refundFreight,
							refundProductAmount, taxFeeAmount, refundCount);

			partProductRefundGoodsReq.setUserId((long) mchId);
			partProductRefundGoodsReq.setCsId(1234L);
			partProductRefundGoodsReq.setPartProductRefundVoList(Arrays
					.asList(partProductRefundVo));
			partProductRefundGoodsReq.setOrderId(orderId);
			partProductRefundGoodsReq.setRemark("部分退货退款");
			partProductRefundGoodsReq.setLiabilityType(1);
			partProductRefundGoodsReq.setRefundExtType(3);
			partProductRefundGoodsReq.setRefundReasonCode(-1);
			partProductRefundGoodsReq.setHasRefundGoods(false);

			partProductRefundGoodsCall.setData(partProductRefundGoodsReq);
			partProductRefundGoodsCall.callService();

			for (RefundBill refundBill : refundBillWrapper
					.selectByOrderId(orderId)) {

				String refundNo = refundBill.getRefund_no();

				// 审核地址
				RefundService.auditRefundGoods(sellerId, sellerId,
						CurrentMchRefundStatusEnum.LEVEL_ONE.getCode(),
						refundNo, true);

				// 上传运单信息
				RefundService.saveOrUpdateRefundGoodsExpressInfoList(sellerId,
						refundNo, sellerId);

				// 审核运单信息
				RefundService.auditRefund(sellerId, sellerId,
						CurrentMchRefundStatusEnum.GOODS.getCode(), refundNo,
						true);
			}

			// 退款服务同步到交易
			RefundService.syncNotSyncedRefundBill();

			// 退款提交到网关
			UserRefundFundDetailPo record = new UserRefundFundDetailPo();

			Calendar calendar = Calendar.getInstance();
			calendar.setTime(new Date());
			calendar.add(Calendar.MINUTE, -6);

			record.setPaymentId(paymentId);
			record.setUpdateTime(calendar.getTime());

			orderShardingWapper.userRefundFundDetailMapper
					.updateByPrimaryKeySelective(record);

			RefundService.supplementRefund(orderId);

			// 支付网关退款回调
			SQPayGateWayCallService.refundNotifyCall("13",
					paymentId.toString(), userId.intValue());

			Thread.sleep(3000);

			// 第二次退自有积分
			calendar.setTime(new Date());
			calendar.add(Calendar.HOUR, -6);

			record.setPaymentId(paymentId);
			record.setUpdateTime(calendar.getTime());

			orderShardingWapper.userRefundFundDetailMapper
					.updateByPrimaryKeySelective(record);

			RefundService.supplementRefund(orderId);


			this.verify(orderId, Arrays.asList(refundedBillNo));

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_PartProductRefundGoods_036() {
		Logger.start(false, "A，B商品换C，带一个普通商品，A商品部分退货退款，不退C商品，退款失败");
		try {

			AgentProductBean productBeanA = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 0, false,
							false);

			AgentProductBean productBeanB = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 0, false,
							false);

			AgentProductBean productBeanC = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 0, false,
							false);

			AgentProductBean normalProductBean = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 0, false,
							false);

			List<AgentProductBean> activityProductBeanList = new ArrayList<>();

			activityProductBeanList.add(productBeanA);
			activityProductBeanList.add(productBeanB);
			activityProductBeanList.add(productBeanC);

			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeOrderWithExchangeBuyList(activityProductBeanList,
							normalProductBean, autotest_goodsOwnerId);

			Order order = placeOrderResp.getOrderList().get(0);

			long sellerId = order.getSellerId();
			Long userId = placeOrderResp.getUserId();

			long orderId = order.getOrderId();

			BigDecimal amount = placeOrderResp.getPayableAmount();

			// 支付订单
			Long thirdTradingId = SqTradingCallService.payOrder(userId,
					placeOrderResp.getTradingId());

			// 支付网关支付回调交易
			SQPayGateWayCallService.DGSQNotifyCall(
					String.valueOf(thirdTradingId),
					amount.subtract(BigDecimal.ZERO).toString(),
					userId.intValue(), BigDecimal.ZERO.toPlainString());

			Thread.sleep(5000);

			// 卖家接单
			SqTradingCallService.sellerAcceptOrder(sellerId, orderId);

			// 发货
			SqTradingCallService.delivery(sellerId, orderId, null, null);

			// 退主商品A一件
			OrderDetailPo orderDetailPo = placeOrderResp
					.getOrderList()
					.get(0)
					.getOrderDetailPoList()
					.stream()
					.filter(OrderDetailPo -> OrderDetailPo.getProductId()
							.equalsIgnoreCase(productBeanA.getProductId()))
					.collect(Collectors.toList()).get(0);

			int refundCount = 1;

			BigDecimal refundTaxAmount = RefundService
					.getOrderDetailTaxFeeAmount(orderDetailPo, refundCount);
			BigDecimal refundProductAmount = RefundService
					.getOrderDetailPaidAmountExcludeFreight(orderDetailPo,
							refundCount, false);
			BigDecimal refundFreightAmount = RefundService
					.getMaxCanRefundFreight(orderDetailPo,
							orderDetailPo.getFreight());

			PartProductRefundVo partProductRefundVo = RefundService
					.buildPartProductRefundVo(orderDetailPo.getCatalogId(),
							refundFreightAmount, refundProductAmount,
							refundTaxAmount, refundCount);

			partProductRefundGoodsReq.setUserId(autotest_goodsOwnerId);
			partProductRefundGoodsReq.setCsId(1234L);
			partProductRefundGoodsReq.setPartProductRefundVoList(Arrays
					.asList(partProductRefundVo));
			partProductRefundGoodsReq.setOrderId(orderId);
			partProductRefundGoodsReq.setRemark("部分退货退款");
			partProductRefundGoodsReq.setLiabilityType(1);
			partProductRefundGoodsReq.setRefundExtType(3);
			partProductRefundGoodsReq.setRefundReasonCode(-1);
			partProductRefundGoodsReq.setHasRefundGoods(false);

			partProductRefundGoodsCall.setData(partProductRefundGoodsReq);
			partProductRefundGoodsCall.callService();

			Logger.verifyEquals("必须包含换购或赠送商品",
					partProductRefundGoodsCall.getMsg(), "验证resultMessage");
			Logger.verifyEquals("3", partProductRefundGoodsCall.getCode(),
					"验证resultCode");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_PartProductRefundGoods_037() {
		Logger.start(false, "A，B商品换C，带一个普通商品，A、B商品部分退货退款，不退C商品，退款失败");
		try {

			AgentProductBean productBeanA = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 0, false,
							false);

			AgentProductBean productBeanB = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 0, false,
							false);

			AgentProductBean productBeanC = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 0, false,
							false);

			AgentProductBean normalProductBean = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 0, false,
							false);

			List<AgentProductBean> activityProductBeanList = new ArrayList<>();

			activityProductBeanList.add(productBeanA);
			activityProductBeanList.add(productBeanB);
			activityProductBeanList.add(productBeanC);

			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeOrderWithExchangeBuyList(activityProductBeanList,
							normalProductBean, autotest_goodsOwnerId);

			Order order = placeOrderResp.getOrderList().get(0);

			long sellerId = order.getSellerId();
			Long userId = placeOrderResp.getUserId();

			long orderId = order.getOrderId();

			BigDecimal amount = placeOrderResp.getPayableAmount();

			// 支付订单
			Long thirdTradingId = SqTradingCallService.payOrder(userId,
					placeOrderResp.getTradingId());

			// 支付网关支付回调交易
			SQPayGateWayCallService.DGSQNotifyCall(
					String.valueOf(thirdTradingId),
					amount.subtract(BigDecimal.ZERO).toString(),
					userId.intValue(), BigDecimal.ZERO.toPlainString());

			Thread.sleep(5000);

			// 卖家接单
			SqTradingCallService.sellerAcceptOrder(sellerId, orderId);

			// 发货
			SqTradingCallService.delivery(sellerId, orderId, null, null);

			// 退主商品A一件
			OrderDetailPo orderDetailPoA = placeOrderResp
					.getOrderList()
					.get(0)
					.getOrderDetailPoList()
					.stream()
					.filter(OrderDetailPo -> OrderDetailPo.getProductId()
							.equalsIgnoreCase(productBeanA.getProductId()))
					.collect(Collectors.toList()).get(0);

			int refundCount = 1;

			BigDecimal refundTaxAmount = RefundService
					.getOrderDetailTaxFeeAmount(orderDetailPoA, refundCount);
			BigDecimal refundProductAmount = RefundService
					.getOrderDetailPaidAmountExcludeFreight(orderDetailPoA,
							refundCount, false);
			BigDecimal refundFreightAmount = RefundService
					.getMaxCanRefundFreight(orderDetailPoA,
							orderDetailPoA.getFreight());

			PartProductRefundVo partProductRefundVoA = RefundService
					.buildPartProductRefundVo(orderDetailPoA.getCatalogId(),
							refundFreightAmount, refundProductAmount,
							refundTaxAmount, refundCount);

			// 退主商品B一件
			OrderDetailPo orderDetailPoB = placeOrderResp
					.getOrderList()
					.get(0)
					.getOrderDetailPoList()
					.stream()
					.filter(OrderDetailPo -> OrderDetailPo.getProductId()
							.equalsIgnoreCase(productBeanB.getProductId()))
					.collect(Collectors.toList()).get(0);

			refundTaxAmount = RefundService.getOrderDetailTaxFeeAmount(
					orderDetailPoB, refundCount);
			refundProductAmount = RefundService
					.getOrderDetailPaidAmountExcludeFreight(orderDetailPoB,
							refundCount, false);
			refundFreightAmount = RefundService.getMaxCanRefundFreight(
					orderDetailPoB, orderDetailPoB.getFreight());

			PartProductRefundVo partProductRefundVoB = RefundService
					.buildPartProductRefundVo(orderDetailPoB.getCatalogId(),
							refundFreightAmount, refundProductAmount,
							refundTaxAmount, refundCount);

			partProductRefundGoodsReq.setUserId(autotest_goodsOwnerId);
			partProductRefundGoodsReq.setCsId(1234L);
			partProductRefundGoodsReq.setPartProductRefundVoList(Arrays.asList(
					partProductRefundVoA, partProductRefundVoB));
			partProductRefundGoodsReq.setOrderId(orderId);
			partProductRefundGoodsReq.setRemark("部分退货退款");
			partProductRefundGoodsReq.setLiabilityType(1);
			partProductRefundGoodsReq.setRefundExtType(3);
			partProductRefundGoodsReq.setRefundReasonCode(-1);
			partProductRefundGoodsReq.setHasRefundGoods(false);

			partProductRefundGoodsCall.setData(partProductRefundGoodsReq);
			partProductRefundGoodsCall.callService();

			Logger.verifyEquals("必须包含换购或赠送商品",
					partProductRefundGoodsCall.getMsg(), "验证resultMessage");
			Logger.verifyEquals("3", partProductRefundGoodsCall.getCode(),
					"验证resultCode");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_PartProductRefundGoods_038() {
		Logger.start(false, "A，B商品换C，带一个普通商品，A商品部分退货退款，C商品退一件，退款失败");
		try {

			AgentProductBean productBeanA = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 0, false,
							false);

			AgentProductBean productBeanB = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 0, false,
							false);

			AgentProductBean productBeanC = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 0, false,
							false);

			AgentProductBean normalProductBean = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 0, false,
							false);

			List<AgentProductBean> activityProductBeanList = new ArrayList<>();

			activityProductBeanList.add(productBeanA);
			activityProductBeanList.add(productBeanB);
			activityProductBeanList.add(productBeanC);

			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeOrderWithExchangeBuyList(activityProductBeanList,
							normalProductBean, autotest_goodsOwnerId);

			Order order = placeOrderResp.getOrderList().get(0);

			long sellerId = order.getSellerId();
			Long userId = placeOrderResp.getUserId();

			long orderId = order.getOrderId();

			BigDecimal amount = placeOrderResp.getPayableAmount();

			// 支付订单
			Long thirdTradingId = SqTradingCallService.payOrder(userId,
					placeOrderResp.getTradingId());

			// 支付网关支付回调交易
			SQPayGateWayCallService.DGSQNotifyCall(
					String.valueOf(thirdTradingId),
					amount.subtract(BigDecimal.ZERO).toString(),
					userId.intValue(), BigDecimal.ZERO.toPlainString());

			Thread.sleep(5000);

			// 卖家接单
			SqTradingCallService.sellerAcceptOrder(sellerId, orderId);

			// 发货
			SqTradingCallService.delivery(sellerId, orderId, null, null);

			// 退主商品A一件
			OrderDetailPo orderDetailPoA = placeOrderResp
					.getOrderList()
					.get(0)
					.getOrderDetailPoList()
					.stream()
					.filter(OrderDetailPo -> OrderDetailPo.getProductId()
							.equalsIgnoreCase(productBeanA.getProductId()))
					.collect(Collectors.toList()).get(0);

			int refundCount = 1;

			BigDecimal refundTaxAmount = RefundService
					.getOrderDetailTaxFeeAmount(orderDetailPoA, refundCount);
			BigDecimal refundProductAmount = RefundService
					.getOrderDetailPaidAmountExcludeFreight(orderDetailPoA,
							refundCount, false);
			BigDecimal refundFreightAmount = RefundService
					.getMaxCanRefundFreight(orderDetailPoA,
							orderDetailPoA.getFreight());

			PartProductRefundVo partProductRefundVoA = RefundService
					.buildPartProductRefundVo(orderDetailPoA.getCatalogId(),
							refundFreightAmount, refundProductAmount,
							refundTaxAmount, refundCount);

			// 换购商品C退一件
			OrderDetailPo orderDetailPoC = placeOrderResp
					.getOrderList()
					.get(0)
					.getOrderDetailPoList()
					.stream()
					.filter(OrderDetailPo -> OrderDetailPo.getProductId()
							.equalsIgnoreCase(productBeanC.getProductId()))
					.collect(Collectors.toList()).get(0);

			refundTaxAmount = RefundService.getOrderDetailTaxFeeAmount(
					orderDetailPoC, refundCount);
			refundProductAmount = RefundService
					.getOrderDetailPaidAmountExcludeFreight(orderDetailPoC,
							refundCount, false);
			refundFreightAmount = RefundService.getMaxCanRefundFreight(
					orderDetailPoC, orderDetailPoC.getFreight());

			PartProductRefundVo partProductRefundVoC = RefundService
					.buildPartProductRefundVo(orderDetailPoC.getCatalogId(),
							refundFreightAmount, refundProductAmount,
							refundTaxAmount, refundCount);

			partProductRefundGoodsReq.setUserId(autotest_goodsOwnerId);
			partProductRefundGoodsReq.setCsId(1234L);
			partProductRefundGoodsReq.setPartProductRefundVoList(Arrays.asList(
					partProductRefundVoA, partProductRefundVoC));
			partProductRefundGoodsReq.setOrderId(orderId);
			partProductRefundGoodsReq.setRemark("部分退货退款");
			partProductRefundGoodsReq.setLiabilityType(1);
			partProductRefundGoodsReq.setRefundExtType(3);
			partProductRefundGoodsReq.setRefundReasonCode(-1);
			partProductRefundGoodsReq.setHasRefundGoods(false);

			partProductRefundGoodsCall.setData(partProductRefundGoodsReq);
			partProductRefundGoodsCall.callService();

			Logger.verifyEquals("关联的换购或赠送商品必须全部退",
					partProductRefundGoodsCall.getMsg(), "验证resultMessage");
			Logger.verifyEquals("3", partProductRefundGoodsCall.getCode(),
					"验证resultCode");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_PartProductRefundGoods_039() {
		Logger.start(false, "A，B商品换C，带一个普通商品，A商品部分退货退款，C商品全退，退款成功");
		try {

			AgentProductBean productBeanA = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 0, false,
							false);

			AgentProductBean productBeanB = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 0, false,
							false);

			AgentProductBean productBeanC = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 0, false,
							false);

			AgentProductBean normalProductBean = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 0, false,
							false);

			List<AgentProductBean> activityProductBeanList = new ArrayList<>();

			activityProductBeanList.add(productBeanA);
			activityProductBeanList.add(productBeanB);
			activityProductBeanList.add(productBeanC);

			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeOrderWithExchangeBuyList(activityProductBeanList,
							normalProductBean, autotest_goodsOwnerId);

			Order order = placeOrderResp.getOrderList().get(0);

			long sellerId = order.getSellerId();
			Long userId = placeOrderResp.getUserId();

			long orderId = order.getOrderId();

			BigDecimal amount = placeOrderResp.getPayableAmount();

			SqTradingMqService.updateLiveOrder(false, orderId);

			// 支付订单
			Long thirdTradingId = SqTradingCallService.payOrder(userId,
					placeOrderResp.getTradingId());

			// 支付网关支付回调交易
			SQPayGateWayCallService.DGSQNotifyCall(
					String.valueOf(thirdTradingId),
					amount.subtract(BigDecimal.ZERO).toString(),
					userId.intValue(), BigDecimal.ZERO.toPlainString());
			
			Thread.sleep(5000);

			Long paymentId = orderShardingWapper.selectOrderbyOrderId(orderId)
					.getPaymentId();

			PaymentPo payment = orderShardingWapper
					.selectPaymentById(paymentId);

			ShenqiSettlementService.onHpSettled(paymentId, payment, null, 1);

			// 卖家接单
			SqTradingCallService.sellerAcceptOrder(sellerId, orderId);

			// 发货
			SqTradingCallService.delivery(sellerId, orderId, null, null);

			// 退主商品A一件
			OrderDetailPo orderDetailPoA = placeOrderResp
					.getOrderList()
					.get(0)
					.getOrderDetailPoList()
					.stream()
					.filter(OrderDetailPo -> OrderDetailPo.getProductId()
							.equalsIgnoreCase(productBeanA.getProductId()))
					.collect(Collectors.toList()).get(0);

			int refundCount = 1;

			BigDecimal refundTaxAmount = RefundService
					.getOrderDetailTaxFeeAmount(orderDetailPoA, refundCount);
			BigDecimal refundProductAmount = RefundService
					.getOrderDetailPaidAmountExcludeFreight(orderDetailPoA,
							refundCount, false);
			BigDecimal refundFreightAmount = RefundService
					.getMaxCanRefundFreight(orderDetailPoA,
							orderDetailPoA.getFreight());

			PartProductRefundVo partProductRefundVoA = RefundService
					.buildPartProductRefundVo(orderDetailPoA.getCatalogId(),
							refundFreightAmount, refundProductAmount,
							refundTaxAmount, refundCount);

			// 换购商品C全退
			OrderDetailPo orderDetailPoC = placeOrderResp
					.getOrderList()
					.get(0)
					.getOrderDetailPoList()
					.stream()
					.filter(OrderDetailPo -> OrderDetailPo.getProductId()
							.equalsIgnoreCase(productBeanC.getProductId()))
					.collect(Collectors.toList()).get(0);

			refundCount = orderDetailPoC.getProductCount();

			refundTaxAmount = RefundService.getOrderDetailTaxFeeAmount(
					orderDetailPoC, refundCount);
			refundProductAmount = RefundService
					.getOrderDetailPaidAmountExcludeFreight(orderDetailPoC,
							refundCount, false);
			refundFreightAmount = RefundService.getMaxCanRefundFreight(
					orderDetailPoC, orderDetailPoC.getFreight());

			PartProductRefundVo partProductRefundVoC = RefundService
					.buildPartProductRefundVo(orderDetailPoC.getCatalogId(),
							refundFreightAmount, refundProductAmount,
							refundTaxAmount, refundCount);

			partProductRefundGoodsReq.setUserId(autotest_goodsOwnerId);
			partProductRefundGoodsReq.setCsId(1234L);
			partProductRefundGoodsReq.setPartProductRefundVoList(Arrays.asList(
					partProductRefundVoA, partProductRefundVoC));
			partProductRefundGoodsReq.setOrderId(orderId);
			partProductRefundGoodsReq.setRemark("部分退货退款");
			partProductRefundGoodsReq.setLiabilityType(1);
			partProductRefundGoodsReq.setRefundExtType(3);
			partProductRefundGoodsReq.setRefundReasonCode(-1);
			partProductRefundGoodsReq.setHasRefundGoods(false);

			partProductRefundGoodsCall.setData(partProductRefundGoodsReq);
			partProductRefundGoodsCall.callService();

			for (RefundBill refundBill : refundBillWrapper
					.selectByOrderId(orderId)) {

				String refundNo = refundBill.getRefund_no();

				// 审核地址
				RefundService.auditRefundGoods(sellerId, sellerId,
						CurrentMchRefundStatusEnum.LEVEL_ONE.getCode(),
						refundNo, true);

				// 上传运单信息
				RefundService.saveOrUpdateRefundGoodsExpressInfoList(sellerId,
						refundNo, sellerId);

				// 审核运单信息
				RefundService.auditRefund(sellerId, sellerId,
						CurrentMchRefundStatusEnum.GOODS.getCode(), refundNo,
						true);
			}

			// 退款服务同步到交易
			RefundService.syncNotSyncedRefundBill();

			// 退款提交到网关
			UserRefundFundDetailPo record = new UserRefundFundDetailPo();

			Calendar calendar = Calendar.getInstance();
			calendar.setTime(new Date());
			calendar.add(Calendar.MINUTE, -6);

			record.setPaymentId(paymentId);
			record.setUpdateTime(calendar.getTime());

			orderShardingWapper.userRefundFundDetailMapper
					.updateByPrimaryKeySelective(record);

			RefundService.supplementRefund(orderId);

			// 支付网关退款回调
			SQPayGateWayCallService.refundNotifyCall("13",
					paymentId.toString(), userId.intValue());

			Thread.sleep(3000);

			this.verify(orderId);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_PartProductRefundGoods_040() {
		Logger.start(false, "A，B商品换C，带一个普通商品，普通商品部分退货退款，退款成功");
		try {

			AgentProductBean productBeanA = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 0, false,
							false);

			AgentProductBean productBeanB = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 0, false,
							false);

			AgentProductBean productBeanC = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 0, false,
							false);

			AgentProductBean normalProductBean = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 0, false,
							false);

			List<AgentProductBean> activityProductBeanList = new ArrayList<>();

			activityProductBeanList.add(productBeanA);
			activityProductBeanList.add(productBeanB);
			activityProductBeanList.add(productBeanC);

			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeOrderWithExchangeBuyList(activityProductBeanList,
							normalProductBean, autotest_goodsOwnerId);

			Order order = placeOrderResp.getOrderList().get(0);

			long sellerId = order.getSellerId();
			Long userId = placeOrderResp.getUserId();

			long orderId = order.getOrderId();

			BigDecimal amount = placeOrderResp.getPayableAmount();

			SqTradingMqService.updateLiveOrder(false, orderId);

			// 支付订单
			Long thirdTradingId = SqTradingCallService.payOrder(userId,
					placeOrderResp.getTradingId());

			// 支付网关支付回调交易
			SQPayGateWayCallService.DGSQNotifyCall(
					String.valueOf(thirdTradingId),
					amount.subtract(BigDecimal.ZERO).toString(),
					userId.intValue(), BigDecimal.ZERO.toPlainString());

			Thread.sleep(5000);

			Long paymentId = orderShardingWapper.selectOrderbyOrderId(orderId)
					.getPaymentId();

			PaymentPo payment = orderShardingWapper
					.selectPaymentById(paymentId);

			ShenqiSettlementService.onHpSettled(paymentId, payment, null, 1);

			// 卖家接单
			SqTradingCallService.sellerAcceptOrder(sellerId, orderId);

			// 发货
			SqTradingCallService.delivery(sellerId, orderId, null, null);

			// 退主商品A一件
			OrderDetailPo orderDetailPoNormal = placeOrderResp
					.getOrderList()
					.get(0)
					.getOrderDetailPoList()
					.stream()
					.filter(OrderDetailPo -> OrderDetailPo.getProductId()
							.equalsIgnoreCase(normalProductBean.getProductId()))
					.collect(Collectors.toList()).get(0);

			int refundCount = 1;

			BigDecimal refundTaxAmount = RefundService
					.getOrderDetailTaxFeeAmount(orderDetailPoNormal,
							refundCount);
			BigDecimal refundProductAmount = RefundService
					.getOrderDetailPaidAmountExcludeFreight(
							orderDetailPoNormal, refundCount, false);
			BigDecimal refundFreightAmount = RefundService
					.getMaxCanRefundFreight(orderDetailPoNormal,
							orderDetailPoNormal.getFreight());

			PartProductRefundVo partProductRefundVoA = RefundService
					.buildPartProductRefundVo(
							orderDetailPoNormal.getCatalogId(),
							refundFreightAmount, refundProductAmount,
							refundTaxAmount, refundCount);

			partProductRefundGoodsReq.setUserId(autotest_goodsOwnerId);
			partProductRefundGoodsReq.setCsId(1234L);
			partProductRefundGoodsReq.setPartProductRefundVoList(Arrays
					.asList(partProductRefundVoA));
			partProductRefundGoodsReq.setOrderId(orderId);
			partProductRefundGoodsReq.setRemark("部分退货退款");
			partProductRefundGoodsReq.setLiabilityType(1);
			partProductRefundGoodsReq.setRefundExtType(3);
			partProductRefundGoodsReq.setRefundReasonCode(-1);
			partProductRefundGoodsReq.setHasRefundGoods(false);

			partProductRefundGoodsCall.setData(partProductRefundGoodsReq);
			partProductRefundGoodsCall.callService();

			for (RefundBill refundBill : refundBillWrapper
					.selectByOrderId(orderId)) {

				String refundNo = refundBill.getRefund_no();

				// 审核地址
				RefundService.auditRefundGoods(autotest_goodsOwnerId,
						autotest_goodsOwnerId,
						CurrentMchRefundStatusEnum.LEVEL_ONE.getCode(),
						refundNo, true);

				// 上传运单信息
				RefundService.saveOrUpdateRefundGoodsExpressInfoList(
						autotest_goodsOwnerId, refundNo, autotest_goodsOwnerId);

				// 审核运单信息
				RefundService.auditRefund(autotest_goodsOwnerId,
						autotest_goodsOwnerId,
						CurrentMchRefundStatusEnum.GOODS.getCode(), refundNo,
						true);
			}

			// 退款服务同步到交易
			RefundService.syncNotSyncedRefundBill();

			// 退款提交到网关
			UserRefundFundDetailPo record = new UserRefundFundDetailPo();

			Calendar calendar = Calendar.getInstance();
			calendar.setTime(new Date());
			calendar.add(Calendar.MINUTE, -6);

			record.setPaymentId(paymentId);
			record.setUpdateTime(calendar.getTime());

			orderShardingWapper.userRefundFundDetailMapper
					.updateByPrimaryKeySelective(record);

			RefundService.supplementRefund(orderId);

			// 支付网关退款回调
			SQPayGateWayCallService.refundNotifyCall("13",
					paymentId.toString(), userId.intValue());

			Thread.sleep(3000);

			this.verify(orderId);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_PartProductRefundGoods_041() {
		Logger.start(false, "A，B商品换C，带一个普通商品，C商品部分退货退款，退款失败");
		try {

			AgentProductBean productBeanA = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 0, false,
							false);

			AgentProductBean productBeanB = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 0, false,
							false);

			AgentProductBean productBeanC = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 0, false,
							false);

			AgentProductBean normalProductBean = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 0, false,
							false);

			List<AgentProductBean> activityProductBeanList = new ArrayList<>();

			activityProductBeanList.add(productBeanA);
			activityProductBeanList.add(productBeanB);
			activityProductBeanList.add(productBeanC);

			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeOrderWithExchangeBuyList(activityProductBeanList,
							normalProductBean, autotest_goodsOwnerId);

			Order order = placeOrderResp.getOrderList().get(0);

			long sellerId = order.getSellerId();
			Long userId = placeOrderResp.getUserId();

			long orderId = order.getOrderId();

			BigDecimal amount = placeOrderResp.getPayableAmount();

			SqTradingMqService.updateLiveOrder(false, orderId);

			// 支付订单
			Long thirdTradingId = SqTradingCallService.payOrder(userId,
					placeOrderResp.getTradingId());

			// 支付网关支付回调交易
			SQPayGateWayCallService.DGSQNotifyCall(
					String.valueOf(thirdTradingId),
					amount.subtract(BigDecimal.ZERO).toString(),
					userId.intValue(), BigDecimal.ZERO.toPlainString());

			Thread.sleep(5000);

			Long paymentId = orderShardingWapper.selectOrderbyOrderId(orderId)
					.getPaymentId();

			PaymentPo payment = orderShardingWapper
					.selectPaymentById(paymentId);

			ShenqiSettlementService.onHpSettled(paymentId, payment, null, 1);

			// 卖家接单
			SqTradingCallService.sellerAcceptOrder(sellerId, orderId);

			// 发货
			SqTradingCallService.delivery(sellerId, orderId, null, null);

			// 退主商品A一件
			OrderDetailPo orderDetailPoC = placeOrderResp
					.getOrderList()
					.get(0)
					.getOrderDetailPoList()
					.stream()
					.filter(OrderDetailPo -> OrderDetailPo.getProductId()
							.equalsIgnoreCase(productBeanC.getProductId()))
					.collect(Collectors.toList()).get(0);

			int refundCount = 1;

			BigDecimal refundTaxAmount = RefundService
					.getOrderDetailTaxFeeAmount(orderDetailPoC, refundCount);
			BigDecimal refundProductAmount = RefundService
					.getOrderDetailPaidAmountExcludeFreight(orderDetailPoC,
							refundCount, false);
			BigDecimal refundFreightAmount = RefundService
					.getMaxCanRefundFreight(orderDetailPoC,
							orderDetailPoC.getFreight());

			PartProductRefundVo partProductRefundVoA = RefundService
					.buildPartProductRefundVo(orderDetailPoC.getCatalogId(),
							refundFreightAmount, refundProductAmount,
							refundTaxAmount, refundCount);

			partProductRefundGoodsReq.setUserId(autotest_goodsOwnerId);
			partProductRefundGoodsReq.setCsId(1234L);
			partProductRefundGoodsReq.setPartProductRefundVoList(Arrays
					.asList(partProductRefundVoA));
			partProductRefundGoodsReq.setOrderId(orderId);
			partProductRefundGoodsReq.setRemark("部分退货退款");
			partProductRefundGoodsReq.setLiabilityType(1);
			partProductRefundGoodsReq.setRefundExtType(3);
			partProductRefundGoodsReq.setRefundReasonCode(-1);
			partProductRefundGoodsReq.setHasRefundGoods(false);

			partProductRefundGoodsCall.setData(partProductRefundGoodsReq);
			partProductRefundGoodsCall.callService();

			Logger.verifyEquals("关联的换购或赠送商品必须全部退",
					partProductRefundGoodsCall.getMsg(), "验证resultMessage");
			Logger.verifyEquals("3", partProductRefundGoodsCall.getCode(),
					"验证resultCode");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_PartProductRefundGoods_042() {
		Logger.start(false, "A，B商品换C，带一个普通商品，C商品全退，退款成功");
		try {

			AgentProductBean productBeanA = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 0, false,
							false);

			AgentProductBean productBeanB = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 0, false,
							false);

			AgentProductBean productBeanC = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 0, false,
							false);

			AgentProductBean normalProductBean = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 0, false,
							false);

			List<AgentProductBean> activityProductBeanList = new ArrayList<>();

			activityProductBeanList.add(productBeanA);
			activityProductBeanList.add(productBeanB);
			activityProductBeanList.add(productBeanC);

			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeOrderWithExchangeBuyList(activityProductBeanList,
							normalProductBean, autotest_goodsOwnerId);

			Order order = placeOrderResp.getOrderList().get(0);

			long sellerId = order.getSellerId();
			Long userId = placeOrderResp.getUserId();

			long orderId = order.getOrderId();

			BigDecimal amount = placeOrderResp.getPayableAmount();

			SqTradingMqService.updateLiveOrder(false, orderId);

			// 支付订单
			Long thirdTradingId = SqTradingCallService.payOrder(userId,
					placeOrderResp.getTradingId());

			// 支付网关支付回调交易
			SQPayGateWayCallService.DGSQNotifyCall(
					String.valueOf(thirdTradingId),
					amount.subtract(BigDecimal.ZERO).toString(),
					userId.intValue(), BigDecimal.ZERO.toPlainString());

			Thread.sleep(5000);

			Long paymentId = orderShardingWapper.selectOrderbyOrderId(orderId)
					.getPaymentId();

			PaymentPo payment = orderShardingWapper
					.selectPaymentById(paymentId);

			ShenqiSettlementService.onHpSettled(paymentId, payment, null, 1);

			// 卖家接单
			SqTradingCallService.sellerAcceptOrder(sellerId, orderId);

			// 发货
			SqTradingCallService.delivery(sellerId, orderId, null, null);

			// 商品C全退
			OrderDetailPo orderDetailPoC = placeOrderResp
					.getOrderList()
					.get(0)
					.getOrderDetailPoList()
					.stream()
					.filter(OrderDetailPo -> OrderDetailPo.getProductId()
							.equalsIgnoreCase(productBeanC.getProductId()))
					.collect(Collectors.toList()).get(0);

			int refundCount = orderDetailPoC.getProductCount();

			BigDecimal refundTaxAmount = RefundService
					.getOrderDetailTaxFeeAmount(orderDetailPoC, refundCount);
			BigDecimal refundProductAmount = RefundService
					.getOrderDetailPaidAmountExcludeFreight(orderDetailPoC,
							refundCount, false);
			BigDecimal refundFreightAmount = RefundService
					.getMaxCanRefundFreight(orderDetailPoC,
							orderDetailPoC.getFreight());

			PartProductRefundVo partProductRefundVoA = RefundService
					.buildPartProductRefundVo(orderDetailPoC.getCatalogId(),
							refundFreightAmount, refundProductAmount,
							refundTaxAmount, refundCount);

			partProductRefundGoodsReq.setUserId(autotest_goodsOwnerId);
			partProductRefundGoodsReq.setCsId(1234L);
			partProductRefundGoodsReq.setPartProductRefundVoList(Arrays
					.asList(partProductRefundVoA));
			partProductRefundGoodsReq.setOrderId(orderId);
			partProductRefundGoodsReq.setRemark("部分退货退款");
			partProductRefundGoodsReq.setLiabilityType(1);
			partProductRefundGoodsReq.setRefundExtType(3);
			partProductRefundGoodsReq.setRefundReasonCode(-1);
			partProductRefundGoodsReq.setHasRefundGoods(false);

			partProductRefundGoodsCall.setData(partProductRefundGoodsReq);
			partProductRefundGoodsCall.callService();

			for (RefundBill refundBill : refundBillWrapper
					.selectByOrderId(orderId)) {

				String refundNo = refundBill.getRefund_no();

				// 审核地址
				RefundService.auditRefundGoods(autotest_goodsOwnerId,
						autotest_goodsOwnerId,
						CurrentMchRefundStatusEnum.LEVEL_ONE.getCode(),
						refundNo, true);

				// 上传运单信息
				RefundService.saveOrUpdateRefundGoodsExpressInfoList(
						autotest_goodsOwnerId, refundNo, autotest_goodsOwnerId);

				// 审核运单信息
				RefundService.auditRefund(autotest_goodsOwnerId,
						autotest_goodsOwnerId,
						CurrentMchRefundStatusEnum.GOODS.getCode(), refundNo,
						true);
			}

			// 退款服务同步到交易
			RefundService.syncNotSyncedRefundBill();

			// 退款提交到网关
			UserRefundFundDetailPo record = new UserRefundFundDetailPo();

			Calendar calendar = Calendar.getInstance();
			calendar.setTime(new Date());
			calendar.add(Calendar.MINUTE, -6);

			record.setPaymentId(paymentId);
			record.setUpdateTime(calendar.getTime());

			orderShardingWapper.userRefundFundDetailMapper
					.updateByPrimaryKeySelective(record);

			RefundService.supplementRefund(orderId);

			// 支付网关退款回调
			SQPayGateWayCallService.refundNotifyCall("13",
					paymentId.toString(), userId.intValue());

			Thread.sleep(3000);

			this.verify(orderId);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_PartProductRefundGoods_043() {
		Logger.start(false, "A，B商品换C，D；1，2商品换3，4，A商品部分退货退款，C商品全退，退款失败");
		try {

			AgentProductBean productBeanA = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 0, false,
							false);

			AgentProductBean productBeanB = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 0, false,
							false);

			AgentProductBean productBeanC = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 0, false,
							false);

			AgentProductBean productBeanD = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 0, false,
							false);

			AgentProductBean productBean1 = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 0, false,
							false);

			AgentProductBean productBean2 = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 0, false,
							false);

			AgentProductBean productBean3 = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 0, false,
							false);

			AgentProductBean productBean4 = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 0, false,
							false);

			AgentProductBean normalProductBean = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 0, false,
							false);

			List<AgentProductBean> activityProductBeanListLetter = new ArrayList<>();

			activityProductBeanListLetter.add(productBeanA);
			activityProductBeanListLetter.add(productBeanB);
			activityProductBeanListLetter.add(productBeanC);
			activityProductBeanListLetter.add(productBeanD);

			List<AgentProductBean> activityProductBeanListNum = new ArrayList<>();

			activityProductBeanListNum.add(productBean1);
			activityProductBeanListNum.add(productBean2);
			activityProductBeanListNum.add(productBean3);
			activityProductBeanListNum.add(productBean4);

			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeOrderWithMultiExchangeBuyList(
							activityProductBeanListLetter,
							activityProductBeanListNum, normalProductBean,
							autotest_goodsOwnerId);

			Order order = placeOrderResp.getOrderList().get(0);

			long sellerId = order.getSellerId();
			Long userId = placeOrderResp.getUserId();

			long orderId = order.getOrderId();

			BigDecimal amount = placeOrderResp.getPayableAmount();

			// 支付订单
			Long thirdTradingId = SqTradingCallService.payOrder(userId,
					placeOrderResp.getTradingId());

			// 支付网关支付回调交易
			SQPayGateWayCallService.DGSQNotifyCall(
					String.valueOf(thirdTradingId),
					amount.subtract(BigDecimal.ZERO).toString(),
					userId.intValue(), BigDecimal.ZERO.toPlainString());

			Thread.sleep(5000);

			// 卖家接单
			SqTradingCallService.sellerAcceptOrder(sellerId, orderId);

			// 发货
			SqTradingCallService.delivery(sellerId, orderId, null, null);

			// 退主商品A一件
			OrderDetailPo orderDetailPoA = placeOrderResp
					.getOrderList()
					.get(0)
					.getOrderDetailPoList()
					.stream()
					.filter(OrderDetailPo -> OrderDetailPo.getProductId()
							.equalsIgnoreCase(productBeanA.getProductId()))
					.collect(Collectors.toList()).get(0);

			int refundCount = 1;

			BigDecimal refundTaxAmount = RefundService
					.getOrderDetailTaxFeeAmount(orderDetailPoA, refundCount);
			BigDecimal refundProductAmount = RefundService
					.getOrderDetailPaidAmountExcludeFreight(orderDetailPoA,
							refundCount, false);
			BigDecimal refundFreightAmount = RefundService
					.getMaxCanRefundFreight(orderDetailPoA,
							orderDetailPoA.getFreight());

			PartProductRefundVo partProductRefundVoA = RefundService
					.buildPartProductRefundVo(orderDetailPoA.getCatalogId(),
							refundFreightAmount, refundProductAmount,
							refundTaxAmount, refundCount);

			// 换购商品C全退
			OrderDetailPo orderDetailPoC = placeOrderResp
					.getOrderList()
					.get(0)
					.getOrderDetailPoList()
					.stream()
					.filter(OrderDetailPo -> OrderDetailPo.getProductId()
							.equalsIgnoreCase(productBeanC.getProductId()))
					.collect(Collectors.toList()).get(0);

			refundCount = orderDetailPoC.getProductCount();

			refundTaxAmount = RefundService.getOrderDetailTaxFeeAmount(
					orderDetailPoC, refundCount);
			refundProductAmount = RefundService
					.getOrderDetailPaidAmountExcludeFreight(orderDetailPoC,
							refundCount, false);
			refundFreightAmount = RefundService.getMaxCanRefundFreight(
					orderDetailPoC, orderDetailPoC.getFreight());

			PartProductRefundVo partProductRefundVoC = RefundService
					.buildPartProductRefundVo(orderDetailPoC.getCatalogId(),
							refundFreightAmount, refundProductAmount,
							refundTaxAmount, refundCount);

			partProductRefundGoodsReq.setUserId(autotest_goodsOwnerId);
			partProductRefundGoodsReq.setCsId(1234L);
			partProductRefundGoodsReq.setPartProductRefundVoList(Arrays.asList(
					partProductRefundVoA, partProductRefundVoC));
			partProductRefundGoodsReq.setOrderId(orderId);
			partProductRefundGoodsReq.setRemark("部分退货退款");
			partProductRefundGoodsReq.setLiabilityType(1);
			partProductRefundGoodsReq.setRefundExtType(3);
			partProductRefundGoodsReq.setRefundReasonCode(-1);
			partProductRefundGoodsReq.setHasRefundGoods(false);

			partProductRefundGoodsCall.setData(partProductRefundGoodsReq);
			partProductRefundGoodsCall.callService();

			Logger.verifyEquals("必须包含换购或赠送商品",
					partProductRefundGoodsCall.getMsg(), "验证resultMessage");
			Logger.verifyEquals("3", partProductRefundGoodsCall.getCode(),
					"验证resultCode");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_PartProductRefundGoods_044() {
		Logger.start(false, "A，B商品换C，D；1，2商品换3，4，A商品部分退货退款，C，D商品全退，3商品退一件，退款成功");
		try {

			AgentProductBean productBeanA = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 0, false,
							false);

			AgentProductBean productBeanB = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 0, false,
							false);

			AgentProductBean productBeanC = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 0, false,
							false);

			AgentProductBean productBeanD = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 0, false,
							false);

			AgentProductBean productBean1 = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 0, false,
							false);

			AgentProductBean productBean2 = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 0, false,
							false);

			AgentProductBean productBean3 = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 0, false,
							false);

			AgentProductBean productBean4 = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 0, false,
							false);

			AgentProductBean normalProductBean = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 0, false,
							false);

			List<AgentProductBean> activityProductBeanListLetter = new ArrayList<>();

			activityProductBeanListLetter.add(productBeanA);
			activityProductBeanListLetter.add(productBeanB);
			activityProductBeanListLetter.add(productBeanC);
			activityProductBeanListLetter.add(productBeanD);

			List<AgentProductBean> activityProductBeanListNum = new ArrayList<>();

			activityProductBeanListNum.add(productBean1);
			activityProductBeanListNum.add(productBean2);
			activityProductBeanListNum.add(productBean3);
			activityProductBeanListNum.add(productBean4);

			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeOrderWithMultiExchangeBuyList(
							activityProductBeanListLetter,
							activityProductBeanListNum, normalProductBean,
							autotest_goodsOwnerId);

			Order order = placeOrderResp.getOrderList().get(0);

			long sellerId = order.getSellerId();
			Long userId = placeOrderResp.getUserId();

			long orderId = order.getOrderId();

			BigDecimal amount = placeOrderResp.getPayableAmount();

			SqTradingMqService.updateLiveOrder(false, orderId);

			// 支付订单
			Long thirdTradingId = SqTradingCallService.payOrder(userId,
					placeOrderResp.getTradingId());

			// 支付网关支付回调交易
			SQPayGateWayCallService.DGSQNotifyCall(
					String.valueOf(thirdTradingId),
					amount.subtract(BigDecimal.ZERO).toString(),
					userId.intValue(), BigDecimal.ZERO.toPlainString());

			Thread.sleep(5000);

			Long paymentId = orderShardingWapper.selectOrderbyOrderId(orderId)
					.getPaymentId();

			PaymentPo payment = orderShardingWapper
					.selectPaymentById(paymentId);

			ShenqiSettlementService.onHpSettled(paymentId, payment, null, 1);

			// 卖家接单
			SqTradingCallService.sellerAcceptOrder(sellerId, orderId);

			// 发货
			SqTradingCallService.delivery(sellerId, orderId, null, null);

			// 退主商品A一件
			OrderDetailPo orderDetailPoA = placeOrderResp
					.getOrderList()
					.get(0)
					.getOrderDetailPoList()
					.stream()
					.filter(OrderDetailPo -> OrderDetailPo.getProductId()
							.equalsIgnoreCase(productBeanA.getProductId()))
					.collect(Collectors.toList()).get(0);

			int refundCount = 1;

			BigDecimal refundTaxAmount = RefundService
					.getOrderDetailTaxFeeAmount(orderDetailPoA, refundCount);
			BigDecimal refundProductAmount = RefundService
					.getOrderDetailPaidAmountExcludeFreight(orderDetailPoA,
							refundCount, false);
			BigDecimal refundFreightAmount = RefundService
					.getMaxCanRefundFreight(orderDetailPoA,
							orderDetailPoA.getFreight());

			PartProductRefundVo partProductRefundVoA = RefundService
					.buildPartProductRefundVo(orderDetailPoA.getCatalogId(),
							refundFreightAmount, refundProductAmount,
							refundTaxAmount, refundCount);

			// 换购商品C全退
			OrderDetailPo orderDetailPoC = placeOrderResp
					.getOrderList()
					.get(0)
					.getOrderDetailPoList()
					.stream()
					.filter(OrderDetailPo -> OrderDetailPo.getProductId()
							.equalsIgnoreCase(productBeanC.getProductId()))
					.collect(Collectors.toList()).get(0);

			refundCount = orderDetailPoC.getProductCount();

			refundTaxAmount = RefundService.getOrderDetailTaxFeeAmount(
					orderDetailPoC, refundCount);
			refundProductAmount = RefundService
					.getOrderDetailPaidAmountExcludeFreight(orderDetailPoC,
							refundCount, false);
			refundFreightAmount = RefundService.getMaxCanRefundFreight(
					orderDetailPoC, orderDetailPoC.getFreight());

			PartProductRefundVo partProductRefundVoC = RefundService
					.buildPartProductRefundVo(orderDetailPoC.getCatalogId(),
							refundFreightAmount, refundProductAmount,
							refundTaxAmount, refundCount);

			// 换购商品D全退
			OrderDetailPo orderDetailPoD = placeOrderResp
					.getOrderList()
					.get(0)
					.getOrderDetailPoList()
					.stream()
					.filter(OrderDetailPo -> OrderDetailPo.getProductId()
							.equalsIgnoreCase(productBeanD.getProductId()))
					.collect(Collectors.toList()).get(0);

			refundCount = orderDetailPoD.getProductCount();

			refundTaxAmount = RefundService.getOrderDetailTaxFeeAmount(
					orderDetailPoD, refundCount);
			refundProductAmount = RefundService
					.getOrderDetailPaidAmountExcludeFreight(orderDetailPoD,
							refundCount, false);
			refundFreightAmount = RefundService.getMaxCanRefundFreight(
					orderDetailPoD, orderDetailPoD.getFreight());

			PartProductRefundVo partProductRefundVoD = RefundService
					.buildPartProductRefundVo(orderDetailPoD.getCatalogId(),
							refundFreightAmount, refundProductAmount,
							refundTaxAmount, refundCount);

			// 换购商品3全退
			OrderDetailPo orderDetailPo3 = placeOrderResp
					.getOrderList()
					.get(0)
					.getOrderDetailPoList()
					.stream()
					.filter(OrderDetailPo -> OrderDetailPo.getProductId()
							.equalsIgnoreCase(productBean3.getProductId()))
					.collect(Collectors.toList()).get(0);

			refundCount = 1;

			refundTaxAmount = RefundService.getOrderDetailTaxFeeAmount(
					orderDetailPo3, refundCount);
			refundProductAmount = RefundService
					.getOrderDetailPaidAmountExcludeFreight(orderDetailPo3,
							refundCount, false);
			refundFreightAmount = RefundService.getMaxCanRefundFreight(
					orderDetailPo3, orderDetailPo3.getFreight());

			PartProductRefundVo partProductRefundVo3 = RefundService
					.buildPartProductRefundVo(orderDetailPo3.getCatalogId(),
							refundFreightAmount, refundProductAmount,
							refundTaxAmount, refundCount);

			partProductRefundGoodsReq.setUserId(autotest_goodsOwnerId);
			partProductRefundGoodsReq.setCsId(1234L);
			partProductRefundGoodsReq.setPartProductRefundVoList(Arrays.asList(
					partProductRefundVoA, partProductRefundVoC,
					partProductRefundVoD, partProductRefundVo3));
			partProductRefundGoodsReq.setOrderId(orderId);
			partProductRefundGoodsReq.setRemark("部分退货退款");
			partProductRefundGoodsReq.setLiabilityType(1);
			partProductRefundGoodsReq.setRefundExtType(3);
			partProductRefundGoodsReq.setRefundReasonCode(-1);
			partProductRefundGoodsReq.setHasRefundGoods(false);

			partProductRefundGoodsCall.setData(partProductRefundGoodsReq);
			partProductRefundGoodsCall.callService();

			for (RefundBill refundBill : refundBillWrapper
					.selectByOrderId(orderId)) {

				String refundNo = refundBill.getRefund_no();

				// 审核地址
				RefundService.auditRefundGoods(autotest_goodsOwnerId,
						autotest_goodsOwnerId,
						CurrentMchRefundStatusEnum.LEVEL_ONE.getCode(),
						refundNo, true);

				// 上传运单信息
				RefundService.saveOrUpdateRefundGoodsExpressInfoList(
						autotest_goodsOwnerId, refundNo, autotest_goodsOwnerId);

				// 审核运单信息
				RefundService.auditRefund(autotest_goodsOwnerId,
						autotest_goodsOwnerId,
						CurrentMchRefundStatusEnum.GOODS.getCode(), refundNo,
						true);
			}

			// 退款服务同步到交易
			RefundService.syncNotSyncedRefundBill();

			// 退款提交到网关
			UserRefundFundDetailPo record = new UserRefundFundDetailPo();

			Calendar calendar = Calendar.getInstance();
			calendar.setTime(new Date());
			calendar.add(Calendar.MINUTE, -6);

			record.setPaymentId(paymentId);
			record.setUpdateTime(calendar.getTime());

			orderShardingWapper.userRefundFundDetailMapper
					.updateByPrimaryKeySelective(record);

			RefundService.supplementRefund(orderId);

			// 支付网关退款回调
			SQPayGateWayCallService.refundNotifyCall("13",
					paymentId.toString(), userId.intValue());

			Thread.sleep(3000);

			this.verify(orderId);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_PartProductRefundGoods_045() {
		Logger.start(false, "A，B商品换C，D；1，2商品换3，4，A，B商品部分退货退款，C，D商品全退，退款成功");
		try {

			AgentProductBean productBeanA = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 0, false,
							false);

			AgentProductBean productBeanB = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 0, false,
							false);

			AgentProductBean productBeanC = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 0, false,
							false);

			AgentProductBean productBeanD = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 0, false,
							false);

			AgentProductBean productBean1 = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 0, false,
							false);

			AgentProductBean productBean2 = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 0, false,
							false);

			AgentProductBean productBean3 = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 0, false,
							false);

			AgentProductBean productBean4 = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 0, false,
							false);

			AgentProductBean normalProductBean = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 0, false,
							false);

			List<AgentProductBean> activityProductBeanListLetter = new ArrayList<>();

			activityProductBeanListLetter.add(productBeanA);
			activityProductBeanListLetter.add(productBeanB);
			activityProductBeanListLetter.add(productBeanC);
			activityProductBeanListLetter.add(productBeanD);

			List<AgentProductBean> activityProductBeanListNum = new ArrayList<>();

			activityProductBeanListNum.add(productBean1);
			activityProductBeanListNum.add(productBean2);
			activityProductBeanListNum.add(productBean3);
			activityProductBeanListNum.add(productBean4);

			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeOrderWithMultiExchangeBuyList(
							activityProductBeanListLetter,
							activityProductBeanListNum, normalProductBean,
							autotest_goodsOwnerId);

			Order order = placeOrderResp.getOrderList().get(0);

			long sellerId = order.getSellerId();
			Long userId = placeOrderResp.getUserId();

			long orderId = order.getOrderId();

			BigDecimal amount = placeOrderResp.getPayableAmount();

			SqTradingMqService.updateLiveOrder(false, orderId);

			// 支付订单
			Long thirdTradingId = SqTradingCallService.payOrder(userId,
					placeOrderResp.getTradingId());

			// 支付网关支付回调交易
			SQPayGateWayCallService.DGSQNotifyCall(
					String.valueOf(thirdTradingId),
					amount.subtract(BigDecimal.ZERO).toString(),
					userId.intValue(), BigDecimal.ZERO.toPlainString());

			Thread.sleep(5000);

			Long paymentId = orderShardingWapper.selectOrderbyOrderId(orderId)
					.getPaymentId();

			PaymentPo payment = orderShardingWapper
					.selectPaymentById(paymentId);

			ShenqiSettlementService.onHpSettled(paymentId, payment, null, 1);

			// 卖家接单
			SqTradingCallService.sellerAcceptOrder(sellerId, orderId);

			// 发货
			SqTradingCallService.delivery(sellerId, orderId, null, null);

			// 退主商品A一件
			OrderDetailPo orderDetailPoA = placeOrderResp
					.getOrderList()
					.get(0)
					.getOrderDetailPoList()
					.stream()
					.filter(OrderDetailPo -> OrderDetailPo.getProductId()
							.equalsIgnoreCase(productBeanA.getProductId()))
					.collect(Collectors.toList()).get(0);

			int refundCount = 1;

			BigDecimal refundTaxAmount = RefundService
					.getOrderDetailTaxFeeAmount(orderDetailPoA, refundCount);
			BigDecimal refundProductAmount = RefundService
					.getOrderDetailPaidAmountExcludeFreight(orderDetailPoA,
							refundCount, false);
			BigDecimal refundFreightAmount = RefundService
					.getMaxCanRefundFreight(orderDetailPoA,
							orderDetailPoA.getFreight());

			PartProductRefundVo partProductRefundVoA = RefundService
					.buildPartProductRefundVo(orderDetailPoA.getCatalogId(),
							refundFreightAmount, refundProductAmount,
							refundTaxAmount, refundCount);

			// 退主商品B一件
			OrderDetailPo orderDetailPoB = placeOrderResp
					.getOrderList()
					.get(0)
					.getOrderDetailPoList()
					.stream()
					.filter(OrderDetailPo -> OrderDetailPo.getProductId()
							.equalsIgnoreCase(productBeanB.getProductId()))
					.collect(Collectors.toList()).get(0);

			refundCount = 1;

			refundTaxAmount = RefundService.getOrderDetailTaxFeeAmount(
					orderDetailPoB, refundCount);
			refundProductAmount = RefundService
					.getOrderDetailPaidAmountExcludeFreight(orderDetailPoB,
							refundCount, false);
			refundFreightAmount = RefundService.getMaxCanRefundFreight(
					orderDetailPoB, orderDetailPoB.getFreight());

			PartProductRefundVo partProductRefundVoB = RefundService
					.buildPartProductRefundVo(orderDetailPoB.getCatalogId(),
							refundFreightAmount, refundProductAmount,
							refundTaxAmount, refundCount);

			// 换购商品C全退
			OrderDetailPo orderDetailPoC = placeOrderResp
					.getOrderList()
					.get(0)
					.getOrderDetailPoList()
					.stream()
					.filter(OrderDetailPo -> OrderDetailPo.getProductId()
							.equalsIgnoreCase(productBeanC.getProductId()))
					.collect(Collectors.toList()).get(0);

			refundCount = orderDetailPoC.getProductCount();

			refundTaxAmount = RefundService.getOrderDetailTaxFeeAmount(
					orderDetailPoC, refundCount);
			refundProductAmount = RefundService
					.getOrderDetailPaidAmountExcludeFreight(orderDetailPoC,
							refundCount, false);
			refundFreightAmount = RefundService.getMaxCanRefundFreight(
					orderDetailPoC, orderDetailPoC.getFreight());

			PartProductRefundVo partProductRefundVoC = RefundService
					.buildPartProductRefundVo(orderDetailPoC.getCatalogId(),
							refundFreightAmount, refundProductAmount,
							refundTaxAmount, refundCount);

			// 换购商品D全退
			OrderDetailPo orderDetailPoD = placeOrderResp
					.getOrderList()
					.get(0)
					.getOrderDetailPoList()
					.stream()
					.filter(OrderDetailPo -> OrderDetailPo.getProductId()
							.equalsIgnoreCase(productBeanD.getProductId()))
					.collect(Collectors.toList()).get(0);

			refundCount = orderDetailPoD.getProductCount();

			refundTaxAmount = RefundService.getOrderDetailTaxFeeAmount(
					orderDetailPoD, refundCount);
			refundProductAmount = RefundService
					.getOrderDetailPaidAmountExcludeFreight(orderDetailPoD,
							refundCount, false);
			refundFreightAmount = RefundService.getMaxCanRefundFreight(
					orderDetailPoD, orderDetailPoD.getFreight());

			PartProductRefundVo partProductRefundVoD = RefundService
					.buildPartProductRefundVo(orderDetailPoD.getCatalogId(),
							refundFreightAmount, refundProductAmount,
							refundTaxAmount, refundCount);

			partProductRefundGoodsReq.setUserId(autotest_goodsOwnerId);
			partProductRefundGoodsReq.setCsId(1234L);
			partProductRefundGoodsReq.setPartProductRefundVoList(Arrays.asList(
					partProductRefundVoA, partProductRefundVoB,
					partProductRefundVoC, partProductRefundVoD));
			partProductRefundGoodsReq.setOrderId(orderId);
			partProductRefundGoodsReq.setRemark("部分退货退款");
			partProductRefundGoodsReq.setLiabilityType(1);
			partProductRefundGoodsReq.setRefundExtType(3);
			partProductRefundGoodsReq.setRefundReasonCode(-1);
			partProductRefundGoodsReq.setHasRefundGoods(false);

			partProductRefundGoodsCall.setData(partProductRefundGoodsReq);
			partProductRefundGoodsCall.callService();

			for (RefundBill refundBill : refundBillWrapper
					.selectByOrderId(orderId)) {

				String refundNo = refundBill.getRefund_no();

				// 审核地址
				RefundService.auditRefundGoods(autotest_goodsOwnerId,
						autotest_goodsOwnerId,
						CurrentMchRefundStatusEnum.LEVEL_ONE.getCode(),
						refundNo, true);

				// 上传运单信息
				RefundService.saveOrUpdateRefundGoodsExpressInfoList(
						autotest_goodsOwnerId, refundNo, autotest_goodsOwnerId);

				// 审核运单信息
				RefundService.auditRefund(autotest_goodsOwnerId,
						autotest_goodsOwnerId,
						CurrentMchRefundStatusEnum.GOODS.getCode(), refundNo,
						true);
			}

			// 退款服务同步到交易
			RefundService.syncNotSyncedRefundBill();

			// 退款提交到网关
			UserRefundFundDetailPo record = new UserRefundFundDetailPo();

			Calendar calendar = Calendar.getInstance();
			calendar.setTime(new Date());
			calendar.add(Calendar.MINUTE, -6);

			record.setPaymentId(paymentId);
			record.setUpdateTime(calendar.getTime());

			orderShardingWapper.userRefundFundDetailMapper
					.updateByPrimaryKeySelective(record);

			RefundService.supplementRefund(orderId);

			// 支付网关退款回调
			SQPayGateWayCallService.refundNotifyCall("13",
					paymentId.toString(), userId.intValue());

			Thread.sleep(3000);

			this.verify(orderId);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_PartProductRefundGoods_047() {
		Logger.start(false, "A，B商品换C，D；1，2商品换3，4，先退商品C，A商品部分退货退款，退款失败");
		try {

			AgentProductBean productBeanA = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 0, false,
							false);

			AgentProductBean productBeanB = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 0, false,
							false);

			AgentProductBean productBeanC = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 0, false,
							false);

			AgentProductBean productBeanD = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 0, false,
							false);

			AgentProductBean productBean1 = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 0, false,
							false);

			AgentProductBean productBean2 = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 0, false,
							false);

			AgentProductBean productBean3 = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 0, false,
							false);

			AgentProductBean productBean4 = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 0, false,
							false);

			AgentProductBean normalProductBean = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 0, false,
							false);

			List<AgentProductBean> activityProductBeanListLetter = new ArrayList<>();

			activityProductBeanListLetter.add(productBeanA);
			activityProductBeanListLetter.add(productBeanB);
			activityProductBeanListLetter.add(productBeanC);
			activityProductBeanListLetter.add(productBeanD);

			List<AgentProductBean> activityProductBeanListNum = new ArrayList<>();

			activityProductBeanListNum.add(productBean1);
			activityProductBeanListNum.add(productBean2);
			activityProductBeanListNum.add(productBean3);
			activityProductBeanListNum.add(productBean4);

			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeOrderWithMultiExchangeBuyList(
							activityProductBeanListLetter,
							activityProductBeanListNum, normalProductBean,
							autotest_goodsOwnerId);

			Order order = placeOrderResp.getOrderList().get(0);

			long sellerId = order.getSellerId();
			Long userId = placeOrderResp.getUserId();

			long orderId = order.getOrderId();

			BigDecimal amount = placeOrderResp.getPayableAmount();

			SqTradingMqService.updateLiveOrder(false, orderId);

			// 支付订单
			Long thirdTradingId = SqTradingCallService.payOrder(userId,
					placeOrderResp.getTradingId());

			// 支付网关支付回调交易
			SQPayGateWayCallService.DGSQNotifyCall(
					String.valueOf(thirdTradingId),
					amount.subtract(BigDecimal.ZERO).toString(),
					userId.intValue(), BigDecimal.ZERO.toPlainString());

			Thread.sleep(5000);

			Long paymentId = orderShardingWapper.selectOrderbyOrderId(orderId)
					.getPaymentId();

			PaymentPo payment = orderShardingWapper
					.selectPaymentById(paymentId);

			ShenqiSettlementService.onHpSettled(paymentId, payment, null, 1);

			// 卖家接单
			SqTradingCallService.sellerAcceptOrder(sellerId, orderId);

			// 发货
			SqTradingCallService.delivery(sellerId, orderId, null, null);

			// 换购商品C全退
			OrderDetailPo orderDetailPoC = placeOrderResp
					.getOrderList()
					.get(0)
					.getOrderDetailPoList()
					.stream()
					.filter(OrderDetailPo -> OrderDetailPo.getProductId()
							.equalsIgnoreCase(productBeanC.getProductId()))
					.collect(Collectors.toList()).get(0);

			RefundService.createOnePartProductRefundSuccess(orderId,
					orderDetailPoC, autotest_goodsOwnerId, paymentId, userId,
					orderDetailPoC.getProductCount());

			// 退主商品A一件
			OrderDetailPo orderDetailPoA = placeOrderResp
					.getOrderList()
					.get(0)
					.getOrderDetailPoList()
					.stream()
					.filter(OrderDetailPo -> OrderDetailPo.getProductId()
							.equalsIgnoreCase(productBeanA.getProductId()))
					.collect(Collectors.toList()).get(0);

			int refundCount = 1;

			BigDecimal refundTaxAmount = RefundService
					.getOrderDetailTaxFeeAmount(orderDetailPoA, refundCount);
			BigDecimal refundProductAmount = RefundService
					.getOrderDetailPaidAmountExcludeFreight(orderDetailPoA,
							refundCount, false);
			BigDecimal refundFreightAmount = RefundService
					.getMaxCanRefundFreight(orderDetailPoA,
							orderDetailPoA.getFreight());

			PartProductRefundVo partProductRefundVoA = RefundService
					.buildPartProductRefundVo(orderDetailPoA.getCatalogId(),
							refundFreightAmount, refundProductAmount,
							refundTaxAmount, refundCount);

			partProductRefundGoodsReq.setUserId(autotest_goodsOwnerId);
			partProductRefundGoodsReq.setCsId(1234L);
			partProductRefundGoodsReq.setPartProductRefundVoList(Arrays
					.asList(partProductRefundVoA));
			partProductRefundGoodsReq.setOrderId(orderId);
			partProductRefundGoodsReq.setRemark("部分退货退款");
			partProductRefundGoodsReq.setLiabilityType(1);
			partProductRefundGoodsReq.setRefundExtType(3);
			partProductRefundGoodsReq.setRefundReasonCode(-1);
			partProductRefundGoodsReq.setHasRefundGoods(false);

			partProductRefundGoodsCall.setData(partProductRefundGoodsReq);
			partProductRefundGoodsCall.callService();

			Logger.verifyEquals("必须包含换购或赠送商品",
					partProductRefundGoodsCall.getMsg(), "验证resultMessage");
			Logger.verifyEquals("3", partProductRefundGoodsCall.getCode(),
					"验证resultCode");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_PartProductRefundGoods_048() {
		Logger.start(false, "A，B商品换C，D；1，2商品换3，4，先退商品C，A商品部分退货退款，D商品全退，退款成功");
		try {

			AgentProductBean productBeanA = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 0, false,
							false);

			AgentProductBean productBeanB = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 0, false,
							false);

			AgentProductBean productBeanC = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 0, false,
							false);

			AgentProductBean productBeanD = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 0, false,
							false);

			AgentProductBean productBean1 = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 0, false,
							false);

			AgentProductBean productBean2 = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 0, false,
							false);

			AgentProductBean productBean3 = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 0, false,
							false);

			AgentProductBean productBean4 = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 0, false,
							false);

			AgentProductBean normalProductBean = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 0, false,
							false);

			List<AgentProductBean> activityProductBeanListLetter = new ArrayList<>();

			activityProductBeanListLetter.add(productBeanA);
			activityProductBeanListLetter.add(productBeanB);
			activityProductBeanListLetter.add(productBeanC);
			activityProductBeanListLetter.add(productBeanD);

			List<AgentProductBean> activityProductBeanListNum = new ArrayList<>();

			activityProductBeanListNum.add(productBean1);
			activityProductBeanListNum.add(productBean2);
			activityProductBeanListNum.add(productBean3);
			activityProductBeanListNum.add(productBean4);

			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeOrderWithMultiExchangeBuyList(
							activityProductBeanListLetter,
							activityProductBeanListNum, normalProductBean,
							autotest_goodsOwnerId);

			Order order = placeOrderResp.getOrderList().get(0);

			long sellerId = order.getSellerId();
			Long userId = placeOrderResp.getUserId();

			long orderId = order.getOrderId();

			BigDecimal amount = placeOrderResp.getPayableAmount();

			SqTradingMqService.updateLiveOrder(false, orderId);

			// 支付订单
			Long thirdTradingId = SqTradingCallService.payOrder(userId,
					placeOrderResp.getTradingId());

			// 支付网关支付回调交易
			SQPayGateWayCallService.DGSQNotifyCall(
					String.valueOf(thirdTradingId),
					amount.subtract(BigDecimal.ZERO).toString(),
					userId.intValue(), BigDecimal.ZERO.toPlainString());

			Thread.sleep(5000);

			Long paymentId = orderShardingWapper.selectOrderbyOrderId(orderId)
					.getPaymentId();

			PaymentPo payment = orderShardingWapper
					.selectPaymentById(paymentId);

			ShenqiSettlementService.onHpSettled(paymentId, payment, null, 1);

			// 卖家接单
			SqTradingCallService.sellerAcceptOrder(sellerId, orderId);

			// 发货
			SqTradingCallService.delivery(sellerId, orderId, null, null);

			// 换购商品C全退
			OrderDetailPo orderDetailPoC = placeOrderResp
					.getOrderList()
					.get(0)
					.getOrderDetailPoList()
					.stream()
					.filter(OrderDetailPo -> OrderDetailPo.getProductId()
							.equalsIgnoreCase(productBeanC.getProductId()))
					.collect(Collectors.toList()).get(0);

			String refundBillNo = RefundService
					.createOnePartProductRefundSuccess(orderId, orderDetailPoC,
							autotest_goodsOwnerId, paymentId, userId,
							orderDetailPoC.getProductCount());

			// 退主商品A一件
			OrderDetailPo orderDetailPoA = placeOrderResp
					.getOrderList()
					.get(0)
					.getOrderDetailPoList()
					.stream()
					.filter(OrderDetailPo -> OrderDetailPo.getProductId()
							.equalsIgnoreCase(productBeanA.getProductId()))
					.collect(Collectors.toList()).get(0);

			int refundCount = 1;

			BigDecimal refundTaxAmount = RefundService
					.getOrderDetailTaxFeeAmount(orderDetailPoA, refundCount);
			BigDecimal refundProductAmount = RefundService
					.getOrderDetailPaidAmountExcludeFreight(orderDetailPoA,
							refundCount, false);
			BigDecimal refundFreightAmount = RefundService
					.getMaxCanRefundFreight(orderDetailPoA,
							orderDetailPoA.getFreight());

			PartProductRefundVo partProductRefundVoA = RefundService
					.buildPartProductRefundVo(orderDetailPoA.getCatalogId(),
							refundFreightAmount, refundProductAmount,
							refundTaxAmount, refundCount);

			// 商品D全退
			OrderDetailPo orderDetailPoD = placeOrderResp
					.getOrderList()
					.get(0)
					.getOrderDetailPoList()
					.stream()
					.filter(OrderDetailPo -> OrderDetailPo.getProductId()
							.equalsIgnoreCase(productBeanD.getProductId()))
					.collect(Collectors.toList()).get(0);

			refundCount = orderDetailPoD.getProductCount();

			refundTaxAmount = RefundService.getOrderDetailTaxFeeAmount(
					orderDetailPoD, refundCount);
			refundProductAmount = RefundService
					.getOrderDetailPaidAmountExcludeFreight(orderDetailPoD,
							refundCount, false);
			refundFreightAmount = RefundService.getMaxCanRefundFreight(
					orderDetailPoD, orderDetailPoD.getFreight());

			PartProductRefundVo partProductRefundVoD = RefundService
					.buildPartProductRefundVo(orderDetailPoD.getCatalogId(),
							refundFreightAmount, refundProductAmount,
							refundTaxAmount, refundCount);

			partProductRefundGoodsReq.setUserId(autotest_goodsOwnerId);
			partProductRefundGoodsReq.setCsId(1234L);
			partProductRefundGoodsReq.setPartProductRefundVoList(Arrays.asList(
					partProductRefundVoA, partProductRefundVoD));
			partProductRefundGoodsReq.setOrderId(orderId);
			partProductRefundGoodsReq.setRemark("部分退货退款");
			partProductRefundGoodsReq.setLiabilityType(1);
			partProductRefundGoodsReq.setRefundExtType(3);
			partProductRefundGoodsReq.setRefundReasonCode(-1);
			partProductRefundGoodsReq.setHasRefundGoods(false);

			partProductRefundGoodsCall.setData(partProductRefundGoodsReq);
			partProductRefundGoodsCall.callService();

			for (RefundBill refundBill : refundBillWrapper
					.selectByOrderId(orderId)) {

				String refundNo = refundBill.getRefund_no();

				// 审核地址
				RefundService.auditRefundGoods(autotest_goodsOwnerId,
						autotest_goodsOwnerId,
						CurrentMchRefundStatusEnum.LEVEL_ONE.getCode(),
						refundNo, true);

				// 上传运单信息
				RefundService.saveOrUpdateRefundGoodsExpressInfoList(
						autotest_goodsOwnerId, refundNo, autotest_goodsOwnerId);

				// 审核运单信息
				RefundService.auditRefund(autotest_goodsOwnerId,
						autotest_goodsOwnerId,
						CurrentMchRefundStatusEnum.GOODS.getCode(), refundNo,
						true);
			}

			// 退款服务同步到交易
			RefundService.syncNotSyncedRefundBill();

			// 退款提交到网关
			UserRefundFundDetailPo record = new UserRefundFundDetailPo();

			Calendar calendar = Calendar.getInstance();
			calendar.setTime(new Date());
			calendar.add(Calendar.MINUTE, -6);

			record.setPaymentId(paymentId);
			record.setUpdateTime(calendar.getTime());

			orderShardingWapper.userRefundFundDetailMapper
					.updateByPrimaryKeySelective(record);

			RefundService.supplementRefund(orderId);

			// 支付网关退款回调
			SQPayGateWayCallService.refundNotifyCall("13",
					paymentId.toString(), userId.intValue());

			Thread.sleep(3000);

			this.verify(orderId, Arrays.asList(refundBillNo));

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_PartProductRefundGoods_049() {
		Logger.start(false, "A，B商品换C，带一个普通商品，C商品修改金额，部分商品退款，退款失败");
		try {

			AgentProductBean productBeanA = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 0, false,
							false);

			AgentProductBean productBeanB = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 0, false,
							false);

			AgentProductBean productBeanC = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 0, false,
							false);

			AgentProductBean normalProductBean = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 0, false,
							false);

			List<AgentProductBean> activityProductBeanList = new ArrayList<>();

			activityProductBeanList.add(productBeanA);
			activityProductBeanList.add(productBeanB);
			activityProductBeanList.add(productBeanC);

			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeOrderWithExchangeBuyList(activityProductBeanList,
							normalProductBean, autotest_goodsOwnerId);

			Order order = placeOrderResp.getOrderList().get(0);

			long sellerId = order.getSellerId();
			Long userId = placeOrderResp.getUserId();

			long orderId = order.getOrderId();

			BigDecimal amount = placeOrderResp.getPayableAmount();

			SqTradingMqService.updateLiveOrder(false, orderId);

			// 支付订单
			Long thirdTradingId = SqTradingCallService.payOrder(userId,
					placeOrderResp.getTradingId());

			// 支付网关支付回调交易
			SQPayGateWayCallService.DGSQNotifyCall(
					String.valueOf(thirdTradingId),
					amount.subtract(BigDecimal.ZERO).toString(),
					userId.intValue(), BigDecimal.ZERO.toPlainString());

			Thread.sleep(5000);

			Long paymentId = orderShardingWapper.selectOrderbyOrderId(orderId)
					.getPaymentId();

			PaymentPo payment = orderShardingWapper
					.selectPaymentById(paymentId);

			ShenqiSettlementService.onHpSettled(paymentId, payment, null, 1);

			// 卖家接单
			SqTradingCallService.sellerAcceptOrder(sellerId, orderId);
			
			// 发货
			SqTradingCallService.delivery(sellerId, orderId, null, null);

			// 退商品C一件
			OrderDetailPo orderDetailPoC = placeOrderResp
					.getOrderList()
					.get(0)
					.getOrderDetailPoList()
					.stream()
					.filter(OrderDetailPo -> OrderDetailPo.getProductId()
							.equalsIgnoreCase(productBeanC.getProductId()))
					.collect(Collectors.toList()).get(0);

			int refundCount = 1;

			PartProductRefundVo partProductRefundVoA = RefundService
					.buildPartProductRefundVo(orderDetailPoC.getCatalogId(),
							BigDecimal.ONE, BigDecimal.ONE, BigDecimal.ZERO,
							refundCount);

			partProductRefundGoodsReq.setUserId(autotest_goodsOwnerId);
			partProductRefundGoodsReq.setCsId(1234L);
			partProductRefundGoodsReq.setPartProductRefundVoList(Arrays
					.asList(partProductRefundVoA));
			partProductRefundGoodsReq.setOrderId(orderId);
			partProductRefundGoodsReq.setRemark("部分退货退款");
			partProductRefundGoodsReq.setLiabilityType(1);
			partProductRefundGoodsReq.setRefundExtType(3);
			partProductRefundGoodsReq.setRefundReasonCode(-1);
			partProductRefundGoodsReq.setHasRefundGoods(false);

			partProductRefundGoodsCall.setData(partProductRefundGoodsReq);
			partProductRefundGoodsCall.callService();

			Logger.verifyEquals("换购或赠送商品退款商品金额不正确",
					partProductRefundGoodsCall.getMsg(), "验证resultMessage");
			Logger.verifyEquals("3", partProductRefundGoodsCall.getCode(),
					"验证resultCode");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_PartProductRefundGoods_051() {
		Logger.start(false, "中免大会员订单，使用积分，已发货，货头申请部分退货退款");
		try {

			CDFMemberService.getCDFMemberUserPoints(cdfMembergoodsOwnerId,
					26080783L);

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createMultiCodeProxychain((int) cdfMembergoodsOwnerId, false);

			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeOrderWithCDFMember(productBean,
							cdfMembergoodsOwnerId, 100L);

			Order order = placeOrderResp.getOrderList().get(0);
			Long userId = placeOrderResp.getUserId();

			long orderId = order.getOrderId();

			BigDecimal amount = placeOrderResp.getPayableAmount();

			SqTradingMqService.updateLiveOrder(false, orderId);

			// 支付订单
			Long thirdTradingId = SqTradingCallService.payOrder(userId,
					placeOrderResp.getTradingId());

			// 支付网关支付回调交易
			SQPayGateWayCallService.DGSQNotifyCall(
					String.valueOf(thirdTradingId),
					amount.subtract(BigDecimal.ZERO).toString(),
					userId.intValue(), BigDecimal.ZERO.toPlainString());

			Thread.sleep(5000);

			Long paymentId = orderShardingWapper.selectOrderbyOrderId(orderId)
					.getPaymentId();

			PaymentPo payment = orderShardingWapper
					.selectPaymentById(paymentId);

			ShenqiSettlementService.onHpSettled(paymentId, payment, null, 1);

			// 卖家接单
			SqTradingCallService.sellerAcceptOrder(cdfMembergoodsOwnerId,
					orderId);

			// 发货
			SqTradingCallService.delivery(cdfMembergoodsOwnerId, orderId,
					null, null);

			OrderDetailPo orderDetailPo = placeOrderResp.getOrderList().get(0)
					.getOrderDetailPoList().get(0);

			int refundCount = orderDetailPo.getProductCount();

			BigDecimal refundTaxAmount = RefundService
					.getOrderDetailTaxFeeAmount(orderDetailPo, refundCount);
			BigDecimal refundProductAmount = RefundService
					.getOrderDetailPaidAmountExcludeFreight(orderDetailPo,
							refundCount, false);
			BigDecimal refundFreightAmount = RefundService
					.getMaxCanRefundFreight(orderDetailPo,
							orderDetailPo.getFreight());
			long refundIntegral = RefundService.getMaxCanRefundIntegral(
					orderDetailPo, refundCount);

			PartProductRefundVo partProductRefundVo = RefundService
					.buildPartProductRefundVo(orderDetailPo.getCatalogId(),
							refundFreightAmount, refundProductAmount,
							refundTaxAmount, refundCount);

			partProductRefundGoodsReq.setUserId(cdfMembergoodsOwnerId);
			partProductRefundGoodsReq.setCsId(1234L);
			partProductRefundGoodsReq.setPartProductRefundVoList(Arrays
					.asList(partProductRefundVo));
			partProductRefundGoodsReq.setOrderId(orderId);
			partProductRefundGoodsReq.setRemark("部分退货退款");
			partProductRefundGoodsReq.setLiabilityType(1);
			partProductRefundGoodsReq.setRefundExtType(3);
			partProductRefundGoodsReq.setRefundReasonCode(-1);
			partProductRefundGoodsReq.setHasRefundGoods(false);
			partProductRefundGoodsReq.setRefundIntegral(refundIntegral);
			partProductRefundGoodsReq.setFilleAmount(BigDecimal.ZERO);

			partProductRefundGoodsCall.setData(partProductRefundGoodsReq);
			partProductRefundGoodsCall.callService();

			for (RefundBill refundBill : refundBillWrapper
					.selectByOrderId(orderId)) {

				String refundNo = refundBill.getRefund_no();

				// 审核地址
				RefundService.auditRefundGoods(cdfMembergoodsOwnerId,
						cdfMembergoodsOwnerId,
						CurrentMchRefundStatusEnum.LEVEL_ONE.getCode(),
						refundNo, true);

				// 上传运单信息
				RefundService.saveOrUpdateRefundGoodsExpressInfoList(
						cdfMembergoodsOwnerId, refundNo, cdfMembergoodsOwnerId);

				// 审核运单信息
				RefundService.auditRefund(cdfMembergoodsOwnerId,
						cdfMembergoodsOwnerId,
						CurrentMchRefundStatusEnum.GOODS.getCode(), refundNo,
						true);
			}

			// 退款服务同步到交易
			RefundService.syncNotSyncedRefundBill();

			for (int i = 0; i < 4; i++) {

				// 退款提交到网关
				UserRefundFundDetailPo record = new UserRefundFundDetailPo();

				Calendar calendar = Calendar.getInstance();
				calendar.setTime(new Date());
				calendar.add(Calendar.MINUTE, -6);

				record.setPaymentId(paymentId);
				record.setUpdateTime(calendar.getTime());

				orderShardingWapper.userRefundFundDetailMapper
						.updateByPrimaryKeySelective(record);

				RefundService.supplementRefund(orderId);

				Thread.sleep(3000);
			}

			// 支付网关退款回调
			SQPayGateWayCallService.refundNotifyCall("13",
					paymentId.toString(), userId.intValue());

			Thread.sleep(3000);

			this.verify(orderId);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_PartProductRefundGoods_052() {
		Logger.start(false, "中免大会员订单，使用积分，已发货，货头申请部分退货退款，退款数量为1");
		try {

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createMultiCodeProxychain((int) cdfMembergoodsOwnerId, false);

			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeOrderWithCDFMember(productBean,
							cdfMembergoodsOwnerId, 10L);

			Order order = placeOrderResp.getOrderList().get(0);

			long sellerId = order.getSellerId();
			Long userId = placeOrderResp.getUserId();

			long orderId = order.getOrderId();

			BigDecimal amount = placeOrderResp.getPayableAmount();

			SqTradingMqService.updateLiveOrder(false, orderId);

			// 支付订单
			Long thirdTradingId = SqTradingCallService.payOrder(userId,
					placeOrderResp.getTradingId());

			// 支付网关支付回调交易
			SQPayGateWayCallService.DGSQNotifyCall(
					String.valueOf(thirdTradingId),
					amount.subtract(BigDecimal.ZERO).toString(),
					userId.intValue(), BigDecimal.ZERO.toPlainString());

			Thread.sleep(5000);

			Long paymentId = orderShardingWapper.selectOrderbyOrderId(orderId)
					.getPaymentId();

			PaymentPo payment = orderShardingWapper
					.selectPaymentById(paymentId);

			ShenqiSettlementService.onHpSettled(paymentId, payment, null, 1);

			// 卖家接单
			SqTradingCallService.sellerAcceptOrder(sellerId, orderId);
			
			// 发货
			SqTradingCallService.delivery(sellerId, orderId, null, null);

			OrderDetailPo orderDetailPo = placeOrderResp.getOrderList().get(0)
					.getOrderDetailPoList().get(0);

			int refundCount = 1;

			BigDecimal refundTaxAmount = RefundService
					.getOrderDetailTaxFeeAmount(orderDetailPo, refundCount);
			BigDecimal refundProductAmount = RefundService
					.getOrderDetailPaidAmountExcludeFreight(orderDetailPo,
							refundCount, false);
			BigDecimal refundFreightAmount = RefundService
					.getMaxCanRefundFreight(orderDetailPo,
							orderDetailPo.getFreight());
			long refundIntegral = RefundService.getMaxCanRefundIntegral(
					orderDetailPo, refundCount);

			PartProductRefundVo partProductRefundVo = RefundService
					.buildPartProductRefundVo(orderDetailPo.getCatalogId(),
							refundFreightAmount, refundProductAmount,
							refundTaxAmount, refundCount);

			partProductRefundGoodsReq.setUserId((long) cdfMembergoodsOwnerId);
			partProductRefundGoodsReq.setCsId(1234L);
			partProductRefundGoodsReq.setPartProductRefundVoList(Arrays
					.asList(partProductRefundVo));
			partProductRefundGoodsReq.setOrderId(orderId);
			partProductRefundGoodsReq.setRemark("部分退货退款");
			partProductRefundGoodsReq.setLiabilityType(1);
			partProductRefundGoodsReq.setRefundExtType(3);
			partProductRefundGoodsReq.setRefundReasonCode(-1);
			partProductRefundGoodsReq.setHasRefundGoods(false);
			partProductRefundGoodsReq.setRefundIntegral(refundIntegral);

			partProductRefundGoodsCall.setData(partProductRefundGoodsReq);
			partProductRefundGoodsCall.callService();

			for (RefundBill refundBill : refundBillWrapper
					.selectByOrderId(orderId)) {

				String refundNo = refundBill.getRefund_no();

				// 审核地址
				RefundService.auditRefundGoods(cdfMembergoodsOwnerId,
						cdfMembergoodsOwnerId,
						CurrentMchRefundStatusEnum.LEVEL_ONE.getCode(),
						refundNo, true);

				// 上传运单信息
				RefundService.saveOrUpdateRefundGoodsExpressInfoList(
						cdfMembergoodsOwnerId, refundNo, cdfMembergoodsOwnerId);

				// 审核运单信息
				RefundService.auditRefund(cdfMembergoodsOwnerId,
						cdfMembergoodsOwnerId,
						CurrentMchRefundStatusEnum.GOODS.getCode(), refundNo,
						true);
			}

			// 退款服务同步到交易
			RefundService.syncNotSyncedRefundBill();
			
			// 退款提交到网关，第一次退积分，第二次退金额
			UserRefundFundDetailPo record = new UserRefundFundDetailPo();

			for (int i = 0; i < 4; i++) {

				Calendar calendar = Calendar.getInstance();
				calendar.setTime(new Date());
				calendar.add(Calendar.MINUTE, -6 * (i + 10));

				record.setPaymentId(paymentId);
				record.setUpdateTime(calendar.getTime());

				orderShardingWapper.userRefundFundDetailMapper
						.updateByPrimaryKeySelective(record);

				RefundService.supplementRefund(orderId);

				Thread.sleep(3000);
			}

			// 支付网关退款回调
			SQPayGateWayCallService.refundNotifyCall("13",
					paymentId.toString(), userId.intValue());

			Thread.sleep(3000);

			this.verify(orderId);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_PartProductRefundGoods_053() {
		Logger.start(false, "中免大会员订单，多个组合商品，使用积分，已发货，货头申请部分退货退款");
		try {

			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeCDFMemberComposeProductOrder(cdfMembergoodsOwnerId,
							100L);

			Order order = placeOrderResp.getOrderList().get(0);

			long sellerId = order.getSellerId();
			Long userId = placeOrderResp.getUserId();

			long orderId = order.getOrderId();

			BigDecimal amount = placeOrderResp.getPayableAmount();

			SqTradingMqService.updateLiveOrder(false, orderId);

			// 支付订单
			Long thirdTradingId = SqTradingCallService.payOrder(userId,
					placeOrderResp.getTradingId());

			// 支付网关支付回调交易
			SQPayGateWayCallService.DGSQNotifyCall(
					String.valueOf(thirdTradingId),
					amount.subtract(BigDecimal.ZERO).toString(),
					userId.intValue(), BigDecimal.ZERO.toPlainString());

			Thread.sleep(5000);

			Long paymentId = orderShardingWapper.selectOrderbyOrderId(orderId)
					.getPaymentId();

			PaymentPo payment = orderShardingWapper
					.selectPaymentById(paymentId);

			ShenqiSettlementService.onHpSettled(paymentId, payment, null, 1);

			// 卖家接单
			SqTradingCallService.sellerAcceptOrder(sellerId, orderId);
			
			// 发货
			SqTradingCallService.delivery(sellerId, orderId, null, null);

			OrderDetailPo orderDetailPo = placeOrderResp.getOrderList().get(0)
					.getOrderDetailPoList().get(0);

			int refundCount = orderDetailPo.getProductCount();

			BigDecimal refundFreight = RefundService.getMaxCanRefundFreight(
					orderDetailPo, orderDetailPo.getFreight());
			BigDecimal refundProductAmount = RefundService
					.getOrderDetailPaidAmountExcludeFreight(orderDetailPo,
							refundCount, false);
			BigDecimal taxFeeAmount = RefundService.getOrderDetailTaxFeeAmount(
					orderDetailPo, refundCount);
			long refundIntegral = RefundService.getMaxCanRefundIntegral(
					orderDetailPo, refundCount);

			PartProductRefundVo partProductRefundVo = RefundService
					.buildPartProductRefundVo(orderDetailPo.getCatalogId(),
							refundFreight, refundProductAmount, taxFeeAmount,
							refundCount);

			partProductRefundGoodsReq.setUserId((long) cdfMembergoodsOwnerId);
			partProductRefundGoodsReq.setCsId(1234L);
			partProductRefundGoodsReq.setPartProductRefundVoList(Arrays
					.asList(partProductRefundVo));
			partProductRefundGoodsReq.setOrderId(orderId);
			partProductRefundGoodsReq.setRemark("部分退货退款");
			partProductRefundGoodsReq.setLiabilityType(1);
			partProductRefundGoodsReq.setRefundExtType(3);
			partProductRefundGoodsReq.setRefundReasonCode(-1);
			partProductRefundGoodsReq.setHasRefundGoods(false);
			partProductRefundGoodsReq.setRefundIntegral(refundIntegral);
			partProductRefundGoodsReq.setFilleAmount(BigDecimal.ZERO);

			partProductRefundGoodsCall.setData(partProductRefundGoodsReq);
			partProductRefundGoodsCall.callService();

			for (RefundBill refundBill : refundBillWrapper
					.selectByOrderId(orderId)) {

				String refundNo = refundBill.getRefund_no();

				// 审核地址
				RefundService.auditRefundGoods(cdfMembergoodsOwnerId,
						cdfMembergoodsOwnerId,
						CurrentMchRefundStatusEnum.LEVEL_ONE.getCode(),
						refundNo, true);

				// 上传运单信息
				RefundService.saveOrUpdateRefundGoodsExpressInfoList(
						cdfMembergoodsOwnerId, refundNo, cdfMembergoodsOwnerId);

				// 审核运单信息
				RefundService.auditRefund(cdfMembergoodsOwnerId,
						cdfMembergoodsOwnerId,
						CurrentMchRefundStatusEnum.GOODS.getCode(), refundNo,
						true);
			}

			// 退款服务同步到交易
			RefundService.syncNotSyncedRefundBill();

			// 退款提交到网关，第一次退积分，第二次退金额
			UserRefundFundDetailPo record = new UserRefundFundDetailPo();

			for (int i = 0; i < 4; i++) {

				Calendar calendar = Calendar.getInstance();
				calendar.setTime(new Date());
				calendar.add(Calendar.MINUTE, -6 * (i + 10));

				record.setPaymentId(paymentId);
				record.setUpdateTime(calendar.getTime());

				orderShardingWapper.userRefundFundDetailMapper
						.updateByPrimaryKeySelective(record);

				RefundService.supplementRefund(orderId);

				Thread.sleep(3000);
			}

			// 支付网关退款回调
			SQPayGateWayCallService.refundNotifyCall("13",
					paymentId.toString(), userId.intValue());

			Thread.sleep(3000);

			this.verify(orderId);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_PartProductRefundGoods_054() {
		Logger.start(false, "中免大会员订单，多商品订单，使用积分，依次退货退款，退款成功");
		try {

			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeCDFMemberComposeProductOrder(cdfMembergoodsOwnerId,
							100L);

			Order order = placeOrderResp.getOrderList().get(0);

			Long userId = placeOrderResp.getUserId();

			long orderId = order.getOrderId();

			BigDecimal amount = placeOrderResp.getPayableAmount();

			SqTradingMqService.updateLiveOrder(false, orderId);

			// 支付订单
			Long thirdTradingId = SqTradingCallService.payOrder(userId,
					placeOrderResp.getTradingId());

			// 支付网关支付回调交易
			SQPayGateWayCallService.DGSQNotifyCall(
					String.valueOf(thirdTradingId),
					amount.subtract(BigDecimal.ZERO).toString(),
					userId.intValue(), BigDecimal.ZERO.toPlainString());

			Thread.sleep(5000);

			Long paymentId = orderShardingWapper.selectOrderbyOrderId(orderId)
					.getPaymentId();

			PaymentPo payment = orderShardingWapper
					.selectPaymentById(paymentId);

			ShenqiSettlementService.onHpSettled(paymentId, payment, null, 1);

			// 卖家接单
			SqTradingCallService.sellerAcceptOrder(cdfMembergoodsOwnerId,
					orderId);

			// 发货
			SqTradingCallService.delivery(cdfMembergoodsOwnerId, orderId, null, null);
			
			for (OrderDetailPo orderDetailPo : order.getOrderDetailPoList()) {

				int refundCount = orderDetailPo.getProductCount();

				BigDecimal refundTaxAmount = RefundService
						.getOrderDetailTaxFeeAmount(orderDetailPo, refundCount);
				BigDecimal refundProductAmount = RefundService
						.getOrderDetailPaidAmountExcludeFreight(orderDetailPo,
								refundCount, false);
				BigDecimal refundFreightAmount = RefundService
						.getMaxCanRefundFreight(orderDetailPo,
								orderDetailPo.getFreight());

				PartProductRefundVo partProductRefundVo = RefundService
						.buildPartProductRefundVo(orderDetailPo.getCatalogId(),
								refundFreightAmount, refundProductAmount,
								refundTaxAmount, refundCount);
				long refundIntegral = RefundService.getMaxCanRefundIntegral(
						orderDetailPo, refundCount);

				partProductRefundGoodsReq.setUserId(cdfMembergoodsOwnerId);
				partProductRefundGoodsReq.setCsId(1234L);
				partProductRefundGoodsReq.setPartProductRefundVoList(Arrays
						.asList(partProductRefundVo));
				partProductRefundGoodsReq.setOrderId(orderId);
				partProductRefundGoodsReq.setRemark("部分退货退款");
				partProductRefundGoodsReq.setLiabilityType(1);
				partProductRefundGoodsReq.setRefundExtType(3);
				partProductRefundGoodsReq.setRefundReasonCode(-1);
				partProductRefundGoodsReq.setHasRefundGoods(false);
				partProductRefundGoodsReq.setRefundIntegral(refundIntegral);
				partProductRefundGoodsReq.setFilleAmount(BigDecimal.ZERO);

				partProductRefundGoodsCall.setData(partProductRefundGoodsReq);
				partProductRefundGoodsCall.callService();

				for (RefundBill refundBill : refundBillWrapper
						.selectByOrderId(orderId)) {

					String refundNo = refundBill.getRefund_no();

					// 审核地址
					RefundService.auditRefundGoods(cdfMembergoodsOwnerId,
							cdfMembergoodsOwnerId,
							CurrentMchRefundStatusEnum.LEVEL_ONE.getCode(),
							refundNo, true);

					// 上传运单信息
					RefundService.saveOrUpdateRefundGoodsExpressInfoList(
							cdfMembergoodsOwnerId, refundNo, cdfMembergoodsOwnerId);

					// 审核运单信息
					RefundService.auditRefund(cdfMembergoodsOwnerId,
							cdfMembergoodsOwnerId,
							CurrentMchRefundStatusEnum.GOODS.getCode(), refundNo,
							true);
				}

				// 退款服务同步到交易
				RefundService.syncNotSyncedRefundBill();

				// 退款提交到网关，第一次退积分，第二次退金额
				UserRefundFundDetailPo record = new UserRefundFundDetailPo();

				for (int i = 0; i < 4; i++) {

					Calendar calendar = Calendar.getInstance();
					calendar.setTime(new Date());
					calendar.add(Calendar.MINUTE, -6 * (i + 10));

					record.setPaymentId(paymentId);
					record.setUpdateTime(calendar.getTime());

					orderShardingWapper.userRefundFundDetailMapper
							.updateByPrimaryKeySelective(record);

					RefundService.supplementRefund(orderId);

					Thread.sleep(3000);
				}

				// 支付网关退款回调
				SQPayGateWayCallService.refundNotifyCall("13",
						paymentId.toString(), userId.intValue());

				Thread.sleep(3000);

				this.verify(orderId);
			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_PartProductRefundGoods_057() {
		Logger.start(false, "中免大会员订单，使用积分，使用所有优惠，货头申请部分退货退款");
		try {

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createMultiCodeProxychain((int) cdfMembergoodsOwnerId, false);

			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeAllPromotionOrderWithCDFMember(productBean,
							cdfMembergoodsOwnerId, 10L, false);

			Order order = placeOrderResp.getOrderList().get(0);

			Long userId = placeOrderResp.getUserId();
			long orderId = order.getOrderId();

			BigDecimal amount = placeOrderResp.getPayableAmount();

			SqTradingMqService.updateLiveOrder(false, orderId);

			// 支付订单
			Long thirdTradingId = SqTradingCallService.payOrder(userId,
					placeOrderResp.getTradingId());

			// 支付网关支付回调交易
			SQPayGateWayCallService.DGSQNotifyCall(
					String.valueOf(thirdTradingId),
					amount.subtract(BigDecimal.ZERO).toString(),
					userId.intValue(), BigDecimal.ZERO.toPlainString());

			Thread.sleep(5000);

			Long paymentId = orderShardingWapper.selectOrderbyOrderId(orderId)
					.getPaymentId();

			PaymentPo payment = orderShardingWapper
					.selectPaymentById(paymentId);

			ShenqiSettlementService.onHpSettled(paymentId, payment, null, 1);

			// 卖家接单
			SqTradingCallService.sellerAcceptOrder(cdfMembergoodsOwnerId,
					orderId);

			// 发货
			SqTradingCallService.delivery(cdfMembergoodsOwnerId, orderId,
					null, null);

			OrderDetailPo orderDetailPo = placeOrderResp.getOrderList().get(0)
					.getOrderDetailPoList().get(0);

			int refundCount = 1;

			BigDecimal refundTaxAmount = RefundService
					.getOrderDetailTaxFeeAmount(orderDetailPo, refundCount);
			BigDecimal refundProductAmount = RefundService
					.getOrderDetailPaidAmountExcludeFreight(orderDetailPo,
							refundCount, false);
			BigDecimal refundFreightAmount = RefundService
					.getMaxCanRefundFreight(orderDetailPo,
							orderDetailPo.getFreight());
			long refundIntegral = RefundService.getMaxCanRefundIntegral(
					orderDetailPo, refundCount);

			PartProductRefundVo partProductRefundVo = RefundService
					.buildPartProductRefundVo(orderDetailPo.getCatalogId(),
							refundFreightAmount, refundProductAmount,
							refundTaxAmount, refundCount);

			partProductRefundGoodsReq.setUserId(cdfMembergoodsOwnerId);
			partProductRefundGoodsReq.setCsId(1234L);
			partProductRefundGoodsReq.setPartProductRefundVoList(Arrays
					.asList(partProductRefundVo));
			partProductRefundGoodsReq.setOrderId(orderId);
			partProductRefundGoodsReq.setRemark("部分退货退款");
			partProductRefundGoodsReq.setLiabilityType(1);
			partProductRefundGoodsReq.setRefundExtType(3);
			partProductRefundGoodsReq.setRefundReasonCode(-1);
			partProductRefundGoodsReq.setHasRefundGoods(false);
			partProductRefundGoodsReq.setRefundIntegral(refundIntegral);
			partProductRefundGoodsReq.setFilleAmount(BigDecimal.ZERO);

			partProductRefundGoodsCall.setData(partProductRefundGoodsReq);
			partProductRefundGoodsCall.callService();

			for (RefundBill refundBill : refundBillWrapper
					.selectByOrderId(orderId)) {

				String refundNo = refundBill.getRefund_no();

				// 审核地址
				RefundService.auditRefundGoods(cdfMembergoodsOwnerId,
						cdfMembergoodsOwnerId,
						CurrentMchRefundStatusEnum.LEVEL_ONE.getCode(),
						refundNo, true);

				// 上传运单信息
				RefundService.saveOrUpdateRefundGoodsExpressInfoList(
						cdfMembergoodsOwnerId, refundNo, cdfMembergoodsOwnerId);

				// 审核运单信息
				RefundService.auditRefund(cdfMembergoodsOwnerId,
						cdfMembergoodsOwnerId,
						CurrentMchRefundStatusEnum.GOODS.getCode(), refundNo,
						true);
			}

			// 退款服务同步到交易
			RefundService.syncNotSyncedRefundBill();

			// 退款提交到网关，第一次退积分，第二次退金额
			UserRefundFundDetailPo record = new UserRefundFundDetailPo();

			for (int i = 0; i < 4; i++) {

				Calendar calendar = Calendar.getInstance();
				calendar.setTime(new Date());
				calendar.add(Calendar.MINUTE, -6 * (i + 10));

				record.setPaymentId(paymentId);
				record.setUpdateTime(calendar.getTime());

				orderShardingWapper.userRefundFundDetailMapper
						.updateByPrimaryKeySelective(record);

				RefundService.supplementRefund(orderId);

				Thread.sleep(3000);
			}

			// 支付网关退款回调
			SQPayGateWayCallService.refundNotifyCall("13",
					paymentId.toString(), userId.intValue());

			Thread.sleep(3000);

			this.verify(orderId);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_PartProductRefundGoods_058() {
		Logger.start(false, "中免大会员订单，使用积分，已发货，货头申请部分退货退款，退款金额为0，退款数量为1");
		try {

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createMultiCodeProxychain((int) cdfMembergoodsOwnerId, false);

			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeOrderWithCDFMember(productBean,
							cdfMembergoodsOwnerId, 10L);

			Order order = placeOrderResp.getOrderList().get(0);

			long sellerId = order.getSellerId();
			Long userId = placeOrderResp.getUserId();

			long orderId = order.getOrderId();

			BigDecimal amount = placeOrderResp.getPayableAmount();

			SqTradingMqService.updateLiveOrder(false, orderId);

			// 支付订单
			Long thirdTradingId = SqTradingCallService.payOrder(userId,
					placeOrderResp.getTradingId());

			// 支付网关支付回调交易
			SQPayGateWayCallService.DGSQNotifyCall(
					String.valueOf(thirdTradingId),
					amount.subtract(BigDecimal.ZERO).toString(),
					userId.intValue(), BigDecimal.ZERO.toPlainString());

			Thread.sleep(5000);

			Long paymentId = orderShardingWapper.selectOrderbyOrderId(orderId)
					.getPaymentId();

			PaymentPo payment = orderShardingWapper
					.selectPaymentById(paymentId);

			ShenqiSettlementService.onHpSettled(paymentId, payment, null, 1);

			// 卖家接单
			SqTradingCallService.sellerAcceptOrder(sellerId, orderId);
			
			// 发货
			SqTradingCallService.delivery(sellerId, orderId, null, null);

			OrderDetailPo orderDetailPo = placeOrderResp.getOrderList().get(0)
					.getOrderDetailPoList().get(0);

			int refundCount = 1;

			BigDecimal refundTaxAmount = RefundService
					.getOrderDetailTaxFeeAmount(orderDetailPo, refundCount);
			BigDecimal refundProductAmount = BigDecimal.ZERO;
			BigDecimal refundFreightAmount = RefundService
					.getMaxCanRefundFreight(orderDetailPo,
							orderDetailPo.getFreight());
			long refundIntegral = RefundService.getMaxCanRefundIntegral(
					orderDetailPo, refundCount);

			PartProductRefundVo partProductRefundVo = RefundService
					.buildPartProductRefundVo(orderDetailPo.getCatalogId(),
							refundFreightAmount, refundProductAmount,
							refundTaxAmount, refundCount);

			partProductRefundGoodsReq.setUserId((long) cdfMembergoodsOwnerId);
			partProductRefundGoodsReq.setCsId(1234L);
			partProductRefundGoodsReq.setPartProductRefundVoList(Arrays
					.asList(partProductRefundVo));
			partProductRefundGoodsReq.setOrderId(orderId);
			partProductRefundGoodsReq.setRemark("部分退货退款");
			partProductRefundGoodsReq.setLiabilityType(1);
			partProductRefundGoodsReq.setRefundExtType(3);
			partProductRefundGoodsReq.setRefundReasonCode(-1);
			partProductRefundGoodsReq.setHasRefundGoods(false);
			partProductRefundGoodsReq.setRefundIntegral(refundIntegral);

			partProductRefundGoodsCall.setData(partProductRefundGoodsReq);
			partProductRefundGoodsCall.callService();

			for (RefundBill refundBill : refundBillWrapper
					.selectByOrderId(orderId)) {

				String refundNo = refundBill.getRefund_no();

				// 审核地址
				RefundService.auditRefundGoods(cdfMembergoodsOwnerId,
						cdfMembergoodsOwnerId,
						CurrentMchRefundStatusEnum.LEVEL_ONE.getCode(),
						refundNo, true);

				// 上传运单信息
				RefundService.saveOrUpdateRefundGoodsExpressInfoList(
						cdfMembergoodsOwnerId, refundNo, cdfMembergoodsOwnerId);

				// 审核运单信息
				RefundService.auditRefund(cdfMembergoodsOwnerId,
						cdfMembergoodsOwnerId,
						CurrentMchRefundStatusEnum.GOODS.getCode(), refundNo,
						true);
			}

			// 退款服务同步到交易
			RefundService.syncNotSyncedRefundBill();
			
			// 退款提交到网关，第一次退积分，第二次退金额
			UserRefundFundDetailPo record = new UserRefundFundDetailPo();

			for (int i = 0; i < 4; i++) {

				Calendar calendar = Calendar.getInstance();
				calendar.setTime(new Date());
				calendar.add(Calendar.MINUTE, -6 * (i + 10));

				record.setPaymentId(paymentId);
				record.setUpdateTime(calendar.getTime());

				orderShardingWapper.userRefundFundDetailMapper
						.updateByPrimaryKeySelective(record);

				RefundService.supplementRefund(orderId);

				Thread.sleep(3000);
			}

			// 支付网关退款回调
			SQPayGateWayCallService.refundNotifyCall("13",
					paymentId.toString(), userId.intValue());

			Thread.sleep(3000);

			this.verify(orderId);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_PartProductRefundGoods_059() {
		Logger.start(false, "一品多码商品订单，部分退货退款");
		try {

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createMultiCodeProxychain((int) multiCDFCodeGoodsOwnerId,
							false);

			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeMultiCDFCodeOrderWithProductCount(productBean,
							multiCDFCodeGoodsOwnerId, 5);

			Order order = placeOrderResp.getOrderList().get(0);

			long sellerId = order.getSellerId();
			Long userId = placeOrderResp.getUserId();

			long orderId = order.getOrderId();

			BigDecimal amount = placeOrderResp.getPayableAmount();

			SqTradingMqService.updateLiveOrder(false, orderId);

			// 支付订单
			Long thirdTradingId = SqTradingCallService.payOrder(userId,
					placeOrderResp.getTradingId());

			// 支付网关支付回调交易
			SQPayGateWayCallService.DGSQNotifyCall(
					String.valueOf(thirdTradingId),
					amount.subtract(BigDecimal.ZERO).toString(),
					userId.intValue(), BigDecimal.ZERO.toPlainString());

			Thread.sleep(5000);

			Long paymentId = orderShardingWapper.selectOrderbyOrderId(orderId)
					.getPaymentId();

			PaymentPo payment = orderShardingWapper
					.selectPaymentById(paymentId);

			ShenqiSettlementService.onHpSettled(paymentId, payment, null, 1);

			// 卖家接单
			SqTradingCallService.sellerAcceptOrder(sellerId, orderId);
			
			// 发货
			SqTradingCallService.delivery(sellerId, orderId, null, null);

			OrderDetailPo orderDetailPo = placeOrderResp.getOrderList().get(0)
					.getOrderDetailPoList().get(0);

			PartProductRefundVo partProductRefundVo = RefundService
					.buildPartProductRefundVo(orderDetailPo.getCatalogId(),
							BigDecimal.ONE, BigDecimal.ONE, BigDecimal.ZERO,
							1);

			partProductRefundGoodsReq.setUserId(multiCDFCodeGoodsOwnerId);
			partProductRefundGoodsReq.setCsId(1234L);
			partProductRefundGoodsReq.setPartProductRefundVoList(Arrays
					.asList(partProductRefundVo));
			partProductRefundGoodsReq.setOrderId(orderId);
			partProductRefundGoodsReq.setRemark("部分退货退款");
			partProductRefundGoodsReq.setLiabilityType(1);
			partProductRefundGoodsReq.setRefundExtType(1);
			partProductRefundGoodsReq.setRefundReasonCode(2);
			partProductRefundGoodsReq.setHasRefundGoods(true);

			partProductRefundGoodsCall.setData(partProductRefundGoodsReq);
			partProductRefundGoodsCall.callService();

			for (RefundBill refundBill : refundBillWrapper
					.selectByOrderId(orderId)) {

				String refundNo = refundBill.getRefund_no();

				// 审核地址
				RefundService.auditRefundGoods(multiCDFCodeGoodsOwnerId,
						multiCDFCodeGoodsOwnerId,
						CurrentMchRefundStatusEnum.LEVEL_ONE.getCode(),
						refundNo, true);

				// 上传运单信息
				RefundService.saveOrUpdateRefundGoodsExpressInfoList(
						multiCDFCodeGoodsOwnerId, refundNo, multiCDFCodeGoodsOwnerId);

				// 审核运单信息
				RefundService.auditRefund(multiCDFCodeGoodsOwnerId,
						multiCDFCodeGoodsOwnerId,
						CurrentMchRefundStatusEnum.GOODS.getCode(), refundNo,
						true);
			}

			// 退款服务同步到交易
			RefundService.syncNotSyncedRefundBill();

			// 退款提交到网关
			UserRefundFundDetailPo record = new UserRefundFundDetailPo();

			Calendar calendar = Calendar.getInstance();
			calendar.setTime(new Date());
			calendar.add(Calendar.MINUTE, -6);

			record.setPaymentId(paymentId);
			record.setUpdateTime(calendar.getTime());

			orderShardingWapper.userRefundFundDetailMapper
					.updateByPrimaryKeySelective(record);

			RefundService.supplementRefund(orderId);

			// 支付网关退款回调
			SQPayGateWayCallService.refundNotifyCall("13",
					paymentId.toString(), userId.intValue());

			Thread.sleep(3000);

			this.verify(orderId);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_PartProductRefundGoods_060() {
		Logger.start(false, "一品多码组合商品订单，部分退货退款");
		try {

			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeMultiCodeComposeProductOrder(multiCDFCodeGoodsOwnerId);

			Order order = placeOrderResp.getOrderList().get(0);

			long sellerId = order.getSellerId();
			Long userId = placeOrderResp.getUserId();

			long orderId = order.getOrderId();

			BigDecimal amount = placeOrderResp.getPayableAmount();

			SqTradingMqService.updateLiveOrder(false, orderId);

			// 支付订单
			Long thirdTradingId = SqTradingCallService.payOrder(userId,
					placeOrderResp.getTradingId());

			// 支付网关支付回调交易
			SQPayGateWayCallService.DGSQNotifyCall(
					String.valueOf(thirdTradingId),
					amount.subtract(BigDecimal.ZERO).toString(),
					userId.intValue(), BigDecimal.ZERO.toPlainString());

			Thread.sleep(5000);

			Long paymentId = orderShardingWapper.selectOrderbyOrderId(orderId)
					.getPaymentId();

			PaymentPo payment = orderShardingWapper
					.selectPaymentById(paymentId);

			ShenqiSettlementService.onHpSettled(paymentId, payment, null, 1);

			// 卖家接单
			SqTradingCallService.sellerAcceptOrder(sellerId, orderId);
			
			// 发货
			SqTradingCallService.delivery(sellerId, orderId, null, null);

			OrderDetailPo orderDetailPo = placeOrderResp.getOrderList().get(0)
					.getOrderDetailPoList().get(0);

			PartProductRefundVo partProductRefundVo = RefundService
					.buildPartProductRefundVo(orderDetailPo.getCatalogId(),
							BigDecimal.ONE, BigDecimal.ONE, BigDecimal.ZERO, 1);

			partProductRefundGoodsReq.setUserId(sellerId);
			partProductRefundGoodsReq.setCsId(1234L);
			partProductRefundGoodsReq.setPartProductRefundVoList(Arrays
					.asList(partProductRefundVo));
			partProductRefundGoodsReq.setOrderId(orderId);
			partProductRefundGoodsReq.setRemark("部分退货退款");
			partProductRefundGoodsReq.setLiabilityType(1);
			partProductRefundGoodsReq.setRefundExtType(1);
			partProductRefundGoodsReq.setRefundReasonCode(2);
			partProductRefundGoodsReq.setHasRefundGoods(true);

			partProductRefundGoodsCall.setData(partProductRefundGoodsReq);
			partProductRefundGoodsCall.callService();

			for (RefundBill refundBill : refundBillWrapper
					.selectByOrderId(orderId)) {

				String refundNo = refundBill.getRefund_no();

				// 审核地址
				RefundService.auditRefundGoods(multiCDFCodeGoodsOwnerId,
						multiCDFCodeGoodsOwnerId,
						CurrentMchRefundStatusEnum.LEVEL_ONE.getCode(),
						refundNo, true);

				// 上传运单信息
				RefundService.saveOrUpdateRefundGoodsExpressInfoList(
						multiCDFCodeGoodsOwnerId, refundNo, multiCDFCodeGoodsOwnerId);

				// 审核运单信息
				RefundService.auditRefund(multiCDFCodeGoodsOwnerId,
						multiCDFCodeGoodsOwnerId,
						CurrentMchRefundStatusEnum.GOODS.getCode(), refundNo,
						true);
			}

			// 退款提交到网关
			UserRefundFundDetailPo record = new UserRefundFundDetailPo();

			for (int i = 0; i < 4; i++) {

				Calendar calendar = Calendar.getInstance();
				calendar.setTime(new Date());
				calendar.add(Calendar.MINUTE, -6 * (i + 10));

				record.setPaymentId(paymentId);
				record.setUpdateTime(calendar.getTime());

				orderShardingWapper.userRefundFundDetailMapper
						.updateByPrimaryKeySelective(record);

				RefundService.supplementRefund(orderId);

				Thread.sleep(3000);
			}

			// 支付网关退款回调
			SQPayGateWayCallService.refundNotifyCall("13",
					paymentId.toString(), userId.intValue());

			Thread.sleep(3000);

			this.verify(orderId);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_PartProductRefundGoods_061() {
		Logger.start(false, "一品多码组合商品订单，使用兑换券，部分退货退款，退兑换券商品");
		try {

			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeMultiCodeComposeProductOrderWithExchangeCoupon(multiCDFCodeGoodsOwnerId);

			Order order = placeOrderResp.getOrderList().get(0);

			long sellerId = order.getSellerId();
			Long userId = placeOrderResp.getUserId();

			long orderId = order.getOrderId();

			BigDecimal amount = placeOrderResp.getPayableAmount();

			SqTradingMqService.updateLiveOrder(false, orderId);

			// 支付订单
			Long thirdTradingId = SqTradingCallService.payOrder(userId,
					placeOrderResp.getTradingId());

			// 支付网关支付回调交易
			SQPayGateWayCallService.DGSQNotifyCall(
					String.valueOf(thirdTradingId),
					amount.subtract(BigDecimal.ZERO).toString(),
					userId.intValue(), BigDecimal.ZERO.toPlainString());

			Thread.sleep(5000);

			Long paymentId = orderShardingWapper.selectOrderbyOrderId(orderId)
					.getPaymentId();

			PaymentPo payment = orderShardingWapper
					.selectPaymentById(paymentId);

			ShenqiSettlementService.onHpSettled(paymentId, payment, null, 1);

			// 卖家接单
			SqTradingCallService.sellerAcceptOrder(sellerId, orderId);
			
			// 发货
			SqTradingCallService.delivery(sellerId, orderId, null, null);

			OrderDetailPo orderDetailPo = placeOrderResp
					.getOrderList()
					.get(0)
					.getOrderDetailPoList()
					.stream()
					.filter(detail -> detail.getCatalogId()
							.startsWith("speecc")).collect(Collectors.toList())
					.get(0);

			PartProductRefundVo partProductRefundVo = RefundService
					.buildPartProductRefundVo(orderDetailPo.getCatalogId(),
							BigDecimal.ZERO, BigDecimal.ZERO, BigDecimal.ZERO, 1);

			partProductRefundGoodsReq.setUserId(sellerId);
			partProductRefundGoodsReq.setCsId(1234L);
			partProductRefundGoodsReq.setPartProductRefundVoList(Arrays
					.asList(partProductRefundVo));
			partProductRefundGoodsReq.setOrderId(orderId);
			partProductRefundGoodsReq.setRemark("部分退货退款");
			partProductRefundGoodsReq.setLiabilityType(1);
			partProductRefundGoodsReq.setRefundExtType(1);
			partProductRefundGoodsReq.setRefundReasonCode(2);
			partProductRefundGoodsReq.setHasRefundGoods(true);

			partProductRefundGoodsCall.setData(partProductRefundGoodsReq);
			partProductRefundGoodsCall.callService();

			for (RefundBill refundBill : refundBillWrapper
					.selectByOrderId(orderId)) {

				String refundNo = refundBill.getRefund_no();

				// 审核地址
				RefundService.auditRefundGoods(multiCDFCodeGoodsOwnerId,
						multiCDFCodeGoodsOwnerId,
						CurrentMchRefundStatusEnum.LEVEL_ONE.getCode(),
						refundNo, true);

				// 上传运单信息
				RefundService.saveOrUpdateRefundGoodsExpressInfoList(
						multiCDFCodeGoodsOwnerId, refundNo, multiCDFCodeGoodsOwnerId);

				// 审核运单信息
				RefundService.auditRefund(multiCDFCodeGoodsOwnerId,
						multiCDFCodeGoodsOwnerId,
						CurrentMchRefundStatusEnum.GOODS.getCode(), refundNo,
						true);
			}
			
			// 退款服务同步到交易
			RefundService.syncNotSyncedRefundBill();		

			this.verify(orderId);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_PartProductRefundGoods_062() {
		Logger.start(false, "直销订单，只有一个商品，使用兑换券，支付金额为0，部分退货退款");
		try {

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 0, false,
							false);

			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeFreeOrderWithExchangeCoupon(productBean,
							productBean.getSellerId());

			Order order = placeOrderResp.getOrderList().get(0);

			long sellerId = order.getSellerId();
			long orderId = order.getOrderId();

			SqTradingMqService.updateLiveOrder(false, orderId);

			// 卖家接单
			SqTradingCallService.sellerAcceptOrder(sellerId, orderId);
			
			Thread.sleep(3000);
			
			// 发货
			SqTradingCallService.delivery(sellerId, orderId, null, null);

			OrderDetailPo orderDetailPo = placeOrderResp
					.getOrderList()
					.get(0)
					.getOrderDetailPoList()
					.stream()
					.filter(detail -> detail.getCatalogId()
							.startsWith("speecc")).collect(Collectors.toList())
					.get(0);

			PartProductRefundVo partProductRefundVo = RefundService
					.buildPartProductRefundVo(orderDetailPo.getCatalogId(),
							BigDecimal.ZERO, BigDecimal.ZERO, BigDecimal.ZERO, 1);

			partProductRefundGoodsReq.setUserId(sellerId);
			partProductRefundGoodsReq.setCsId(1234L);
			partProductRefundGoodsReq.setPartProductRefundVoList(Arrays
					.asList(partProductRefundVo));
			partProductRefundGoodsReq.setOrderId(orderId);
			partProductRefundGoodsReq.setRemark("部分退货退款");
			partProductRefundGoodsReq.setLiabilityType(1);
			partProductRefundGoodsReq.setRefundExtType(1);
			partProductRefundGoodsReq.setRefundReasonCode(2);
			partProductRefundGoodsReq.setHasRefundGoods(true);

			partProductRefundGoodsCall.setData(partProductRefundGoodsReq);
			partProductRefundGoodsCall.callService();

			for (RefundBill refundBill : refundBillWrapper
					.selectByOrderId(orderId)) {

				String refundNo = refundBill.getRefund_no();

				// 审核地址
				RefundService.auditRefundGoods(autotest_goodsOwnerId,
						autotest_goodsOwnerId,
						CurrentMchRefundStatusEnum.LEVEL_ONE.getCode(),
						refundNo, true);

				// 上传运单信息
				RefundService.saveOrUpdateRefundGoodsExpressInfoList(
						autotest_goodsOwnerId, refundNo, autotest_goodsOwnerId);

				// 审核运单信息
				RefundService.auditRefund(autotest_goodsOwnerId,
						autotest_goodsOwnerId,
						CurrentMchRefundStatusEnum.GOODS.getCode(), refundNo,
						true);
			}
			
			// 退款服务同步到交易
			RefundService.syncNotSyncedRefundBill();		

			this.verify(orderId);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_PartProductRefundGoods_063() {
		Logger.start(false, "直销订单，商家通知自提，已发货，自提点未确认收货，货头申请部分退货退款");
		try {

			AgentProductBean productBean = DGSQBuildProxyChainCallService
					.createProxychain((int) autotest_goodsOwnerId, 0, false,
							false);

			TradingServiceResp placeOrderResp = SqTradingCallService
					.placeOrderWithPickupType(productBean,
							autotest_goodsOwnerId, 1);

			Order order = placeOrderResp.getOrderList().get(0);

			long sellerId = order.getSellerId();
			Long userId = placeOrderResp.getUserId();

			long orderId = order.getOrderId();

			BigDecimal amount = placeOrderResp.getPayableAmount();

			SqTradingMqService.updateLiveOrder(false, orderId);

			// 支付订单
			Long thirdTradingId = SqTradingCallService.payOrder(userId,
					placeOrderResp.getTradingId());

			// 支付网关支付回调交易
			SQPayGateWayCallService.DGSQNotifyCall(
					String.valueOf(thirdTradingId),
					amount.subtract(BigDecimal.ZERO).toString(),
					userId.intValue(), BigDecimal.ZERO.toPlainString());

			Thread.sleep(5000);

			Long paymentId = orderShardingWapper.selectOrderbyOrderId(orderId)
					.getPaymentId();

			PaymentPo payment = orderShardingWapper
					.selectPaymentById(paymentId);

			ShenqiSettlementService.onHpSettled(paymentId, payment, null, 1);

			// 卖家接单
			SqTradingCallService.sellerAcceptOrder(sellerId, orderId);

			// 发货
			SqTradingCallService.delivery(sellerId, orderId, null, null);

			OrderDetailPo orderDetailPo = placeOrderResp.getOrderList().get(0)
					.getOrderDetailPoList().get(0);

			PartProductRefundVo partProductRefundVo = RefundService
					.buildPartProductRefundVo(orderDetailPo.getCatalogId(),
							BigDecimal.ONE, BigDecimal.ONE, BigDecimal.ONE, 1);

			partProductRefundGoodsReq.setUserId(autotest_goodsOwnerId);
			partProductRefundGoodsReq.setCsId(1234L);
			partProductRefundGoodsReq.setPartProductRefundVoList(Arrays
					.asList(partProductRefundVo));
			partProductRefundGoodsReq.setOrderId(orderId);
			partProductRefundGoodsReq.setRemark("部分退货退款");
			partProductRefundGoodsReq.setLiabilityType(1);
			partProductRefundGoodsReq.setRefundExtType(3);
			partProductRefundGoodsReq.setRefundReasonCode(-1);
			partProductRefundGoodsReq.setHasRefundGoods(false);

			partProductRefundGoodsCall.setData(partProductRefundGoodsReq);
			partProductRefundGoodsCall.callService();

			Logger.verifyEquals("商家通知型自提订单, 自提点未收到货时暂时无法发起退款~", partProductRefundGoodsCall.getMsg(),
					"验证resultMessage");
			Logger.verifyEquals("3", partProductRefundGoodsCall.getCode(), "验证resultCode");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P3.class)
	@TestCase
	public void PRD_BUG_TEST1() {
		Logger.start(false, "直销订单，已发货，货头申请部分退货退款");
		try {

			TradingServiceResp placeOrderResp = SqTradingCallService
					.PRD_BUG_TEST1();

			Order order = placeOrderResp.getOrderList().get(0);

			long sellerId = order.getSellerId();
			Long userId = placeOrderResp.getUserId();

			long orderId = order.getOrderId();

			BigDecimal amount = placeOrderResp.getPayableAmount();

			SqTradingMqService.updateLiveOrder(false, orderId);

			// 支付订单
			Long thirdTradingId = SqTradingCallService.payOrder(userId,
					placeOrderResp.getTradingId());

			// 支付网关支付回调交易
			SQPayGateWayCallService.DGSQNotifyCall(
					String.valueOf(thirdTradingId),
					amount.subtract(BigDecimal.ZERO).toString(),
					userId.intValue(), BigDecimal.ZERO.toPlainString());

			Thread.sleep(5000);

			Long paymentId = orderShardingWapper.selectOrderbyOrderId(orderId)
					.getPaymentId();

			PaymentPo payment = orderShardingWapper
					.selectPaymentById(paymentId);

			ShenqiSettlementService.onHpSettled(paymentId, payment, null, 1);

			// 卖家接单
			SqTradingCallService.sellerAcceptOrder(sellerId, orderId);
			
			RefundService.createPartAmountRefundSuccess(orderId, sellerId,
					paymentId, userId, BigDecimal.TEN);

			// 发货
			SqTradingCallService.delivery(sellerId, orderId, null, null);

			OrderDetailPo orderDetailPo = placeOrderResp.getOrderList().get(0)
					.getOrderDetailPoList().get(1);

			PartProductRefundVo partProductRefundVo = RefundService
					.buildPartProductRefundVo(orderDetailPo.getCatalogId(),
							BigDecimal.ZERO, BigDecimal.ONE, BigDecimal.ZERO, 1);

			partProductRefundGoodsReq.setUserId(sellerId);
			partProductRefundGoodsReq.setCsId(1234L);
			partProductRefundGoodsReq.setPartProductRefundVoList(Arrays
					.asList(partProductRefundVo));
			partProductRefundGoodsReq.setOrderId(orderId);
			partProductRefundGoodsReq.setRemark("部分退货退款");
			partProductRefundGoodsReq.setLiabilityType(1);
			partProductRefundGoodsReq.setRefundExtType(3);
			partProductRefundGoodsReq.setRefundReasonCode(-1);
			partProductRefundGoodsReq.setHasRefundGoods(false);

			partProductRefundGoodsCall.setData(partProductRefundGoodsReq);
			partProductRefundGoodsCall.callService();

			for (RefundBill refundBill : refundBillWrapper
					.selectByOrderId(orderId)) {

				String refundNo = refundBill.getRefund_no();

				// 审核地址
				RefundService.auditRefundGoods(sellerId,
						sellerId,
						CurrentMchRefundStatusEnum.LEVEL_ONE.getCode(),
						refundNo, true);

				// 上传运单信息
				RefundService.saveOrUpdateRefundGoodsExpressInfoList(
						sellerId, refundNo, sellerId);

				// 审核运单信息
				RefundService.auditRefund(sellerId,
						sellerId,
						CurrentMchRefundStatusEnum.GOODS.getCode(), refundNo,
						true);
			}
			
			// 退款服务同步到交易
			RefundService.syncNotSyncedRefundBill();

			// 退款提交到网关
			UserRefundFundDetailPo record = new UserRefundFundDetailPo();

			Calendar calendar = Calendar.getInstance();
			calendar.setTime(new Date());
			calendar.add(Calendar.MINUTE, -6);

			record.setPaymentId(paymentId);
			record.setUpdateTime(calendar.getTime());

			orderShardingWapper.userRefundFundDetailMapper
					.updateByPrimaryKeySelective(record);

			RefundService.supplementRefund(orderId);

			// 支付网关退款回调
			SQPayGateWayCallService.refundNotifyCall("13",
					paymentId.toString(), userId.intValue());

			Thread.sleep(3000);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	public static void main(String[] args) throws Exception {

		// Ts_PartProductRefund test = new Ts_PartProductRefund();
		//
		// Long orderId = 13096838699L;
		//
		// partProductRefundReq = new PartProductRefundReq();
		//
		// PartProductRefundVo partProductRefundVo = RefundService
		// .buildPartProductRefundVo("c8789955", new BigDecimal("11.00"),
		// new BigDecimal("2628.00"), new BigDecimal("448.64"), 2);
		//
		// partProductRefundReq.setOrderId(orderId);
		// partProductRefundReq.setUserId((long) autotest_goodsOwnerId);
		// partProductRefundReq.setCsId(1234L);
		// partProductRefundReq.setRemark("部分退货退款");
		// partProductRefundReq.setPartProductRefundVoList(Arrays
		// .asList(partProductRefundVo));
		//
		// test.verify(orderId, Arrays.asList("TH201208000135583"));

		// 支付网关退款回调
		SQPayGateWayCallService.refundNotifyCall("13", "1710029840", 502239840);
	}
}
